diff --git a/src/AutoQuery.AspNetCore/AutoQueryServiceExtensions.cs b/src/AutoQuery.AspNetCore/AutoQueryServiceExtensions.cs index b38658a..a536dab 100644 --- a/src/AutoQuery.AspNetCore/AutoQueryServiceExtensions.cs +++ b/src/AutoQuery.AspNetCore/AutoQueryServiceExtensions.cs @@ -8,16 +8,16 @@ namespace Microsoft.AspNetCore.Builder; /// -/// 提供查詢服務相關的擴展方法。 +/// Provides extension methods related to query services. /// public static class AutoQueryServiceExtensions { /// - /// 向服務集合中添加查詢建構器服務。 + /// Adds query builder services to the service collection. /// - /// 服務集合。 - /// 要應用配置的程序集。 - /// 更新後的服務集合。 + /// The service collection. + /// The assembly to apply configurations from. + /// The updated service collection. public static IServiceCollection AddAutoQuery(this IServiceCollection services, Assembly assembly) { ArgumentNullException.ThrowIfNull(services); diff --git a/src/AutoQuery.AspNetCore/EnableFieldProjectionAttribute.cs b/src/AutoQuery.AspNetCore/EnableFieldProjectionAttribute.cs index 8921855..52c5656 100644 --- a/src/AutoQuery.AspNetCore/EnableFieldProjectionAttribute.cs +++ b/src/AutoQuery.AspNetCore/EnableFieldProjectionAttribute.cs @@ -13,7 +13,7 @@ namespace AutoQuery.AspNetCore; /// -/// 字段投影屬性,用於在返回結果中僅包含指定的字段。 +/// Field projection attribute used to include only specified fields in the returned result. /// public class EnableFieldProjectionAttribute : ActionFilterAttribute { @@ -24,18 +24,18 @@ public class EnableFieldProjectionAttribute : ActionFilterAttribute private IQueryOptions? _queryOptions; /// - /// 在操作執行之前調用,從操作參數中提取 QueryOptions。 + /// Called before the action is executed to extract QueryOptions from the action parameters. /// - /// 操作執行上下文。 + /// The action execution context. public override void OnActionExecuting(ActionExecutingContext context) { _queryOptions = ExtractQueryOptions(context); } /// - /// 在操作執行之後調用,根據指定的字段過濾返回結果。 + /// Called after the action is executed to filter the returned result based on the specified fields. /// - /// 操作執行上下文。 + /// The action execution context. public override void OnActionExecuted(ActionExecutedContext context) { if (_queryOptions == null || string.IsNullOrEmpty(_queryOptions.Fields)) @@ -53,12 +53,12 @@ public override void OnActionExecuted(ActionExecutedContext context) } /// - /// 過濾結果,僅包含選擇的字段。 + /// Filters the result to include only the selected fields. /// - /// 要過濾的對象。 - /// 選擇的字段集合。 - /// JSON 序列化選項。 - /// 過濾後的對象。 + /// The object to filter. + /// The set of selected fields. + /// JSON serialization options. + /// The filtered object. private static object FilterResult(object value, HashSet selectedFields, JsonSerializerOptions serializerOptions) { if (value is IEnumerable enumerable) @@ -76,12 +76,12 @@ private static object FilterResult(object value, HashSet selectedFields, } /// - /// 過濾集合類型的結果。 + /// Filters a collection-type result. /// - /// 要過濾的集合。 - /// 選擇的字段集合。 - /// JSON 序列化選項。 - /// 過濾後的集合。 + /// The collection to filter. + /// The set of selected fields. + /// JSON serialization options. + /// The filtered collection. private static List> FilterEnumerable(IEnumerable enumerable, HashSet selectedFields, JsonSerializerOptions serializerOptions) { var result = new List>(); @@ -94,13 +94,13 @@ private static object FilterResult(object value, HashSet selectedFields, } /// - /// 過濾單個物件的結果。 + /// Filters the result of a single object. /// - /// 要過濾的物件。 - /// 選擇的字段集合。 - /// JSON 序列化選項。 - /// 是否僅過濾第一層屬性。 - /// 過濾後的字典。 + /// The object to filter. + /// The set of selected fields. + /// JSON serialization options. + /// Whether to filter only the first-level properties. + /// The filtered dictionary. private static Dictionary FilterObject(object value, HashSet selectedFields, JsonSerializerOptions serializerOptions, bool firstLevelOnly = false) { var result = new Dictionary(); @@ -138,20 +138,20 @@ private static object FilterResult(object value, HashSet selectedFields, } /// - /// 從操作上下文中提取 QueryOptions。 + /// Extracts QueryOptions from the action context. /// - /// 操作執行上下文。 - /// 提取的 QueryOptions。 + /// The action execution context. + /// The extracted QueryOptions. private static IQueryOptions? ExtractQueryOptions(ActionExecutingContext context) { return context.ActionArguments.Values.OfType().FirstOrDefault(); } /// - /// 解析選擇的字段。 + /// Parses the selected fields. /// - /// 逗號分隔的字段名稱。 - /// 選擇的字段集合。 + /// Comma-separated field names. + /// The set of selected fields. private static HashSet ParseSelectedFields(string fields) { return fields.Split(',') @@ -160,21 +160,21 @@ private static HashSet ParseSelectedFields(string fields) } /// - /// 獲取 JSON 序列化選項。 + /// Gets the JSON serialization options. /// - /// 操作執行上下文。 - /// JSON 序列化選項。 + /// The action execution context. + /// The JSON serialization options. private static JsonSerializerOptions GetSerializerOptions(ActionExecutedContext context) { return context.HttpContext.RequestServices.GetRequiredService>().Value.JsonSerializerOptions; } /// - /// 使用表達樹取得屬性的值。 + /// Gets the value of a property using expression trees. /// - /// 屬性信息。 - /// 對象實例。 - /// 屬性的值。 + /// The property information. + /// The object instance. + /// The value of the property. private static object? GetPropertyValue(PropertyInfo property, object instance) { if (!_propertyAccessorsCache.TryGetValue(property, out var accessor)) @@ -191,11 +191,11 @@ private static JsonSerializerOptions GetSerializerOptions(ActionExecutedContext } /// - /// 獲取屬性的 JSON 屬性名稱。 + /// Gets the JSON property name of a property. /// - /// 屬性信息。 - /// JSON 序列化選項。 - /// 屬性的 JSON 名稱。 + /// The property information. + /// JSON serialization options. + /// The JSON name of the property. private static string GetJsonPropertyName(PropertyInfo propInfo, JsonSerializerOptions serializerOptions) { var jsonPropertyNameAttr = _jsonPropertyNameCache[propInfo]; @@ -205,9 +205,9 @@ private static string GetJsonPropertyName(PropertyInfo propInfo, JsonSerializerO } /// - /// 緩存類型的屬性信息。 + /// Caches the property information of a type. /// - /// 要緩存的類型。 + /// The type to cache. private static void CacheProperties(Type type) { if (!_propertyInfoCache.ContainsKey(type)) @@ -224,10 +224,10 @@ private static void CacheProperties(Type type) } /// - /// 確定狀態碼是否表示成功。 + /// Determines whether the status code indicates success. /// - /// HTTP 狀態碼。 - /// 如果狀態碼表示成功,則為 true;否則為 false。 + /// The HTTP status code. + /// True if the status code indicates success; otherwise, false. private static bool IsSuccessStatusCode(int statusCode) { return statusCode >= 200 && statusCode < 300; diff --git a/src/AutoQuery/Abstractions/IFilterExpressionBuilder.cs b/src/AutoQuery/Abstractions/IFilterExpressionBuilder.cs index 4872cc8..674a41f 100644 --- a/src/AutoQuery/Abstractions/IFilterExpressionBuilder.cs +++ b/src/AutoQuery/Abstractions/IFilterExpressionBuilder.cs @@ -3,16 +3,16 @@ namespace AutoQuery.Abstractions; /// -/// 定義篩選查詢屬性建構器的介面。 +/// Defines the interface for a filter query property builder. /// -/// 數據的類型。 -/// 查詢屬性的類型。 +/// The type of the data. +/// The type of the query property. public interface IFilterExpressionBuilder { /// - /// 構建篩選表達式。 + /// Builds the filter expression. /// - /// 篩選屬性的值。 - /// 篩選表達式。 + /// The value of the filter property. + /// The filter expression. Expression> BuildFilterExpression(TQueryProperty filterValue); } diff --git a/src/AutoQuery/Abstractions/IFilterQueryConfiguration.cs b/src/AutoQuery/Abstractions/IFilterQueryConfiguration.cs index 3fbdb73..dce5611 100644 --- a/src/AutoQuery/Abstractions/IFilterQueryConfiguration.cs +++ b/src/AutoQuery/Abstractions/IFilterQueryConfiguration.cs @@ -1,15 +1,15 @@ namespace AutoQuery.Abstractions; /// -/// 定義篩選查詢配置的介面。 +/// Defines the interface for filter query configuration. /// -/// 查詢選項的類型。 -/// 數據的類型。 +/// The type of the query options. +/// The type of the data. public interface IFilterQueryConfiguration { /// - /// 配置篩選查詢建構器。 + /// Configures the filter query builder. /// - /// 篩選查詢建構器。 + /// The filter query builder. void Configure(FilterQueryBuilder builder); } diff --git a/src/AutoQuery/Abstractions/IQueryOptions.cs b/src/AutoQuery/Abstractions/IQueryOptions.cs index 68dbc16..715e8a3 100644 --- a/src/AutoQuery/Abstractions/IQueryOptions.cs +++ b/src/AutoQuery/Abstractions/IQueryOptions.cs @@ -1,17 +1,17 @@ namespace AutoQuery.Abstractions; /// -/// 查詢參數 +/// Query parameters. /// public interface IQueryOptions { /// - /// 選擇的欄位 + /// Selected fields. /// string? Fields { get; set; } /// - /// 排序欄位 + /// Sorting fields. /// string? Sort { get; set; } } diff --git a/src/AutoQuery/Abstractions/IQueryPagedOptions.cs b/src/AutoQuery/Abstractions/IQueryPagedOptions.cs index 2067869..fcfdd3e 100644 --- a/src/AutoQuery/Abstractions/IQueryPagedOptions.cs +++ b/src/AutoQuery/Abstractions/IQueryPagedOptions.cs @@ -1,17 +1,17 @@ namespace AutoQuery.Abstractions; /// -/// 查詢已分頁參數 +/// Query parameters for paginated results. /// public interface IQueryPagedOptions : IQueryOptions { /// - /// 當前頁數 + /// Current page number. /// int? Page { get; set; } /// - /// 每頁資料數量 + /// Number of items per page. /// int? PageSize { get; set; } } diff --git a/src/AutoQuery/Abstractions/IQueryProcessor.cs b/src/AutoQuery/Abstractions/IQueryProcessor.cs index 5dd69e8..b588233 100644 --- a/src/AutoQuery/Abstractions/IQueryProcessor.cs +++ b/src/AutoQuery/Abstractions/IQueryProcessor.cs @@ -3,27 +3,27 @@ namespace AutoQuery.Abstractions; /// -/// 定義查詢建構器服務的介面。 +/// Defines the interface for query builder services. /// public interface IQueryProcessor { /// - /// 構建篩選表達式。 + /// Builds the filter expression. /// - /// 數據的類型。 - /// 查詢選項的類型。 - /// 查詢選項。 - /// 篩選表達式,如果沒有篩選條件則為 null。 + /// The type of the data. + /// The type of the query options. + /// The query options. + /// The filter expression, or null if no filter conditions exist. Expression>? BuildFilterExpression(TQueryOptions queryOptions) where TQueryOptions : IQueryOptions; /// - /// 構建選擇器表達式。 + /// Builds the selector expression. /// - /// 數據的類型。 - /// 查詢選項的類型。 - /// 查詢選項。 - /// 選擇器表達式,如果沒有選擇條件則為 null。 + /// The type of the data. + /// The type of the query options. + /// The query options. + /// The selector expression, or null if no selection conditions exist. Expression>? BuildSelectorExpression(TQueryOptions queryOptions) where TQueryOptions : IQueryOptions; } diff --git a/src/AutoQuery/ComplexFilterQueryPropertyBuilder.cs b/src/AutoQuery/ComplexFilterQueryPropertyBuilder.cs index 65ed2b4..e1c4a89 100644 --- a/src/AutoQuery/ComplexFilterQueryPropertyBuilder.cs +++ b/src/AutoQuery/ComplexFilterQueryPropertyBuilder.cs @@ -5,30 +5,30 @@ namespace AutoQuery; /// -/// 用於構建篩選查詢屬性的建構器類別。 +/// A builder class for constructing filter query properties. /// -/// 數據的類型。 -/// 查詢屬性的類型。 -/// 數據屬性的類型。 +/// The type of the data. +/// The type of the query property. +/// The type of the data property. public class ComplexFilterQueryPropertyBuilder : IFilterExpressionBuilder { private Expression> _filterKeySelector; private List<(Expression> Expression, LogicalOperator Logical)> _filterExpressions = new(); /// - /// 初始化 類別的新實例。 + /// Initializes a new instance of the class. /// - /// 數據中的篩選鍵選擇器。 + /// The filter key selector in the data. public ComplexFilterQueryPropertyBuilder(Expression> filterKeySelector) { _filterKeySelector = filterKeySelector; } /// - /// 添加篩選表達式。 + /// Adds a filter expression. /// - /// 篩選表達式。 - /// 邏輯運算符。 + /// The filter expression. + /// The logical operator. public void AddFilterExpression(Expression> filterExpression, LogicalOperator logicalOperator) { _filterExpressions.Add((filterExpression, logicalOperator)); @@ -56,4 +56,4 @@ public Expression> BuildFilterExpression(TQueryProperty filter return Expression.Lambda>(finalExpression ?? Expression.Constant(true), parameter); } -} \ No newline at end of file +} diff --git a/src/AutoQuery/Extensions/ComplexFilterQueryPropertyBuilderExtensions.cs b/src/AutoQuery/Extensions/ComplexFilterQueryPropertyBuilderExtensions.cs index 887be2b..add3a45 100644 --- a/src/AutoQuery/Extensions/ComplexFilterQueryPropertyBuilderExtensions.cs +++ b/src/AutoQuery/Extensions/ComplexFilterQueryPropertyBuilderExtensions.cs @@ -5,7 +5,7 @@ namespace AutoQuery.Extensions; /// -/// 提供擴充方法來建立篩選查詢屬性建構器。 +/// Provides extension methods for creating filter query property builders. /// public static class ComplexFilterQueryPropertyBuilderExtensions { @@ -21,14 +21,14 @@ static ComplexFilterQueryPropertyBuilderExtensions() } /// - /// 添加相等篩選條件。 + /// Adds an equality filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The logical operator. + /// The updated filter query property builder. public static ComplexFilterQueryPropertyBuilder HasEqual( this ComplexFilterQueryPropertyBuilder builder, LogicalOperator logicalOperator = LogicalOperator.AND) { @@ -36,14 +36,14 @@ public static ComplexFilterQueryPropertyBuilder - /// 添加不相等篩選條件。 + /// Adds a not-equal filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The logical operator. + /// The updated filter query property builder. public static ComplexFilterQueryPropertyBuilder HasNotEqual( this ComplexFilterQueryPropertyBuilder builder, LogicalOperator logicalOperator = LogicalOperator.AND) { @@ -51,14 +51,14 @@ public static ComplexFilterQueryPropertyBuilder - /// 添加大於或等於篩選條件。 + /// Adds a greater-than-or-equal filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The logical operator. + /// The updated filter query property builder. public static ComplexFilterQueryPropertyBuilder HasGreaterThanOrEqual( this ComplexFilterQueryPropertyBuilder builder, LogicalOperator logicalOperator = LogicalOperator.AND) { @@ -66,14 +66,14 @@ public static ComplexFilterQueryPropertyBuilder - /// 添加大於篩選條件。 + /// Adds a greater-than filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The logical operator. + /// The updated filter query property builder. public static ComplexFilterQueryPropertyBuilder HasGreaterThan( this ComplexFilterQueryPropertyBuilder builder, LogicalOperator logicalOperator = LogicalOperator.AND) { @@ -81,14 +81,14 @@ public static ComplexFilterQueryPropertyBuilder - /// 添加小於或等於篩選條件。 + /// Adds a less-than-or-equal filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The logical operator. + /// The updated filter query property builder. public static ComplexFilterQueryPropertyBuilder HasLessThanOrEqual( this ComplexFilterQueryPropertyBuilder builder, LogicalOperator logicalOperator = LogicalOperator.AND) { @@ -96,14 +96,14 @@ public static ComplexFilterQueryPropertyBuilder - /// 添加小於篩選條件。 + /// Adds a less-than filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The logical operator. + /// The updated filter query property builder. public static ComplexFilterQueryPropertyBuilder HasLessThan( this ComplexFilterQueryPropertyBuilder builder, LogicalOperator logicalOperator = LogicalOperator.AND) { @@ -111,14 +111,14 @@ public static ComplexFilterQueryPropertyBuilder - /// 添加集合包含篩選條件。 + /// Adds a collection contains filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The logical operator. + /// The updated filter query property builder. public static ComplexFilterQueryPropertyBuilder HasCollectionContains( this ComplexFilterQueryPropertyBuilder builder, LogicalOperator logicalOperator = LogicalOperator.AND) { @@ -133,14 +133,14 @@ public static ComplexFilterQueryPropertyBuilder - /// 添加字符串包含篩選條件。 + /// Adds a string contains filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The logical operator. + /// The updated filter query property builder. public static ComplexFilterQueryPropertyBuilder HasStringContains( this ComplexFilterQueryPropertyBuilder builder, LogicalOperator logicalOperator = LogicalOperator.AND) { @@ -148,14 +148,14 @@ public static ComplexFilterQueryPropertyBuilder - /// 添加字符串開頭篩選條件。 + /// Adds a string starts-with filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The logical operator. + /// The updated filter query property builder. public static ComplexFilterQueryPropertyBuilder HasStringStartsWith( this ComplexFilterQueryPropertyBuilder builder, LogicalOperator logicalOperator = LogicalOperator.AND) { @@ -163,15 +163,15 @@ public static ComplexFilterQueryPropertyBuilder - /// 添加自定義篩選條件。 + /// Adds a custom filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 自定義篩選表達式。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The custom filter expression. + /// The logical operator. + /// The updated filter query property builder. public static ComplexFilterQueryPropertyBuilder HasCustomFilter( this ComplexFilterQueryPropertyBuilder builder, Expression> customFilter, LogicalOperator logicalOperator = LogicalOperator.AND) @@ -181,15 +181,15 @@ public static ComplexFilterQueryPropertyBuilder - /// 添加比較篩選條件。 + /// Adds a comparison filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 比較類型。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The type of comparison. + /// The logical operator. + /// The updated filter query property builder. private static ComplexFilterQueryPropertyBuilder AddComparisonFilter( ComplexFilterQueryPropertyBuilder builder, ExpressionType comparisonType, LogicalOperator logicalOperator) { @@ -203,15 +203,15 @@ private static ComplexFilterQueryPropertyBuilder - /// 添加字符串篩選條件。 + /// Adds a string filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 字符串方法。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The type of the data property. + /// The filter query property builder. + /// The string method. + /// The logical operator. + /// The updated filter query property builder. [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static ComplexFilterQueryPropertyBuilder AddStringFilter( ComplexFilterQueryPropertyBuilder builder, MethodInfo stringMethod, LogicalOperator logicalOperator) @@ -232,13 +232,13 @@ internal static ComplexFilterQueryPropertyBuilder - /// 創建集合包含條件。 + /// Creates a collection contains condition. /// - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 查詢屬性參數。 - /// 數據屬性參數。 - /// 集合包含條件表達式。 + /// The type of the query property. + /// The type of the data property. + /// The query property parameter. + /// The data property parameter. + /// The collection contains condition expression. [MethodImpl(MethodImplOptions.AggressiveInlining)] private static BinaryExpression CreateCollectionContainsCondition(ParameterExpression parameterA, ParameterExpression parameterB) { @@ -249,7 +249,7 @@ private static BinaryExpression CreateCollectionContainsCondition).MakeGenericType(valueTypeB).GetMethod(nameof(ICollection.Contains), new[] { valueTypeB }) - ?? throw new Exception("未能找到 ICollection.Contains 方法。"); + ?? throw new Exception("Failed to find ICollection.Contains method."); var condition = Expression.Call(parameterA, method, valueB); return Expression.AndAlso(Expression.AndAlso(notNullA, hasValueB), condition); } @@ -257,7 +257,7 @@ private static BinaryExpression CreateCollectionContainsCondition).GetMethod(nameof(ICollection.Contains), new[] { typeof(TDataProperty) }) - ?? throw new Exception("未能找到 ICollection.Contains 方法。"); + ?? throw new Exception("Failed to find ICollection.Contains method."); var condition = Expression.Call(parameterA, method, parameterB); return Expression.AndAlso(notNullA, condition); } @@ -266,19 +266,19 @@ private static BinaryExpression CreateCollectionContainsCondition).GetMethod(nameof(ICollection.Contains), new[] { typeof(TDataProperty) }) - ?? throw new Exception("未能找到 ICollection.Contains 方法。"); + ?? throw new Exception("Failed to find ICollection.Contains method."); var condition = Expression.Call(parameterA, method, parameterB); return Expression.AndAlso(Expression.AndAlso(notNullA, notNullB), condition); } } /// - /// 創建比較條件。 + /// Creates a comparison condition. /// - /// 查詢屬性參數。 - /// 數據屬性參數。 - /// 比較類型。 - /// 比較條件表達式。 + /// The query property parameter. + /// The data property parameter. + /// The type of comparison. + /// The comparison condition expression. [MethodImpl(MethodImplOptions.AggressiveInlining)] private static BinaryExpression CreateComparisonCondition(ParameterExpression parameterA, ParameterExpression parameterB, ExpressionType comparisonType) { diff --git a/src/AutoQuery/Extensions/ExpressionExtensions.cs b/src/AutoQuery/Extensions/ExpressionExtensions.cs index f098e1c..6c96099 100644 --- a/src/AutoQuery/Extensions/ExpressionExtensions.cs +++ b/src/AutoQuery/Extensions/ExpressionExtensions.cs @@ -6,17 +6,17 @@ namespace AutoQuery.Extensions; /// -/// 提供擴展方法來處理表達式樹。 +/// Provides extension methods for working with expression trees. /// public static class ExpressionExtensions { /// - /// 替換表達式中的參數。 + /// Replaces a parameter in an expression. /// - /// 要替換的舊參數。 - /// 新的參數表達式。 - /// 包含參數的表達式主體。 - /// 替換後的表達式。 + /// The old parameter to replace. + /// The new parameter expression. + /// The body of the expression containing the parameter. + /// The expression with the parameter replaced. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Expression ReplaceParameter(ParameterExpression oldParam, Expression newParam, Expression body) { @@ -24,14 +24,14 @@ public static Expression ReplaceParameter(ParameterExpression oldParam, Expressi } /// - /// 替換表達式中的多個參數。 + /// Replaces multiple parameters in an expression. /// - /// 要替換的舊參數1。 - /// 新的參數表達式1。 - /// 要替換的舊參數2。 - /// 新的參數表達式2。 - /// 包含參數的表達式主體。 - /// 替換後的表達式。 + /// The first old parameter to replace. + /// The first new parameter expression. + /// The second old parameter to replace. + /// The second new parameter expression. + /// The body of the expression containing the parameters. + /// The expression with the parameters replaced. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Expression ReplaceParameters(ParameterExpression oldParam1, Expression newParam1, ParameterExpression oldParam2, Expression newParam2, Expression body) { @@ -39,12 +39,12 @@ public static Expression ReplaceParameters(ParameterExpression oldParam1, Expres } /// - /// 組合兩個表達式,使用指定的邏輯運算符。 + /// Combines two expressions using the specified logical operator. /// - /// 左側表達式。 - /// 右側表達式。 - /// 邏輯運算符。 - /// 組合後的表達式。 + /// The left expression. + /// The right expression. + /// The logical operator. + /// The combined expression. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Expression CombineExpressions(Expression left, Expression right, LogicalOperator logical) { @@ -52,13 +52,13 @@ public static Expression CombineExpressions(Expression left, Expression right, L } /// - /// 獲取成員訪問路徑。 + /// Gets the member access path. /// - /// Lambda 表達式。 - /// 是否僅允許第一層成員。 - /// 是否在錯誤時返回 null 而不是拋出異常。 - /// 成員訪問路徑,如果有錯誤且 為 true,則返回 null。 - /// 為 true 且有多層成員時,或當表達式不是成員訪問時拋出。 + /// The lambda expression. + /// Whether to allow only first-level members. + /// Whether to return null instead of throwing an exception on error. + /// The member access path, or null if an error occurs and is true. + /// Thrown if is true and there are multiple levels of members, or if the expression is not a member access. public static string? GetMemberPath(this LambdaExpression lambda, bool firstLevelOnly = false, bool noError = false) { List list = new List(); @@ -95,10 +95,10 @@ public static Expression CombineExpressions(Expression left, Expression right, L } /// - /// 判斷 Lambda 表達式是否為身份表達式。 + /// Determines whether a lambda expression is an identity expression. /// - /// Lambda 表達式。 - /// 如果是身份表達式,返回 true;否則返回 false。 + /// The lambda expression. + /// True if it is an identity expression; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsIdentity(this LambdaExpression lambda) { @@ -112,11 +112,11 @@ public static bool IsIdentity(this LambdaExpression lambda) } /// - /// 修剪表達式中的轉換操作。 + /// Trims conversion operations from an expression. /// - /// 要修剪的表達式。 - /// 是否強制修剪所有轉換操作。 - /// 修剪後的表達式。 + /// The expression to trim. + /// Whether to force trimming all conversion operations. + /// The trimmed expression. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Expression TrimConversion(this Expression exp, bool force = false) { @@ -135,11 +135,11 @@ public static Expression TrimConversion(this Expression exp, bool force = false) } /// - /// 判斷類型是否可以從另一個類型引用分配。 + /// Determines whether a type can be reference-assigned from another type. /// - /// 目標類型。 - /// 源類型。 - /// 如果可以引用分配,返回 true;否則返回 false。 + /// The destination type. + /// The source type. + /// True if reference assignment is possible; otherwise, false. [MethodImpl(MethodImplOptions.AggressiveInlining)] private static bool IsReferenceAssignableFrom(this Type destType, Type srcType) { diff --git a/src/AutoQuery/Extensions/QueryExtensions.cs b/src/AutoQuery/Extensions/QueryExtensions.cs index ab75ef5..8fe02c9 100644 --- a/src/AutoQuery/Extensions/QueryExtensions.cs +++ b/src/AutoQuery/Extensions/QueryExtensions.cs @@ -6,7 +6,7 @@ namespace AutoQuery.Extensions; /// -/// 提供查詢擴展方法。 +/// Provides query extension methods. /// public static class QueryExtensions { @@ -14,14 +14,14 @@ public static class QueryExtensions private static readonly ConcurrentDictionary s_PropertyCache = new(); /// - /// 應用查詢條件。 + /// Applies query conditions. /// - /// 查詢的實體類型。 - /// 查詢選項的類型。 - /// 查詢對象。 - /// 查詢處理對象。 - /// 查詢選項。 - /// 應用查詢條件後的查詢對象。 + /// The type of the entity being queried. + /// The type of the query options. + /// The query object. + /// The query processor object. + /// The query options. + /// The query object with conditions applied. public static IQueryable ApplyQuery(this IQueryable query, IQueryProcessor queryProcessor, TQueryOptions queryOption) where TQueryOptions : IQueryOptions { @@ -35,14 +35,14 @@ public static IQueryable ApplyQuery(this IQueryable } /// - /// 應用查詢條件和分頁選項。 + /// Applies query conditions and pagination options. /// - /// 查詢的實體類型。 - /// 查詢選項的類型。 - /// 查詢對象。 - /// 查詢建構器。 - /// 查詢選項。 - /// 應用查詢條件和分頁選項後的查詢對象。 + /// The type of the entity being queried. + /// The type of the query options. + /// The query object. + /// The query processor. + /// The query options. + /// The query object with conditions and pagination options applied. public static PagedResult ApplyQueryPaged(this IQueryable query, IQueryProcessor queryProcessor, TQueryOptions queryOption) where TQueryOptions : IQueryPagedOptions where TData : class @@ -63,12 +63,12 @@ public static PagedResult ApplyQueryPaged(this IQue } /// - /// 對查詢結果應用排序。 + /// Applies sorting to the query results. /// - /// 查詢的實體類型。 - /// 查詢對象。 - /// 查詢選項。 - /// 排序後的查詢結果。 + /// The type of the entity being queried. + /// The query object. + /// The query options. + /// The sorted query results. public static IQueryable ApplySort(this IQueryable query, IQueryOptions queryOption) { if (string.IsNullOrWhiteSpace(queryOption.Sort)) @@ -100,12 +100,12 @@ public static IQueryable ApplySort(this IQueryable query, IQueryOptions } /// - /// 根據查詢條件進行分頁。 + /// Applies pagination to the query results. /// - /// 查詢的實體類型。 - /// 查詢對象。 - /// 查詢選項。 - /// 應用分頁後的查詢對象。 + /// The type of the entity being queried. + /// The query object. + /// The query options. + /// The query object with pagination applied. public static IQueryable ApplyPaging(this IQueryable query, IQueryPagedOptions queryOption) { if (queryOption.PageSize.HasValue) diff --git a/src/AutoQuery/Extensions/SimpleFilterQueryPropertyBuilderExtensions.cs b/src/AutoQuery/Extensions/SimpleFilterQueryPropertyBuilderExtensions.cs index d2782b6..76b70ef 100644 --- a/src/AutoQuery/Extensions/SimpleFilterQueryPropertyBuilderExtensions.cs +++ b/src/AutoQuery/Extensions/SimpleFilterQueryPropertyBuilderExtensions.cs @@ -5,7 +5,7 @@ namespace AutoQuery.Extensions; /// -/// 提供擴充方法來建立篩選查詢屬性建構器。 +/// Provides extension methods for creating filter query property builders. /// public static class SimpleFilterQueryPropertyBuilderExtensions { @@ -15,20 +15,20 @@ public static class SimpleFilterQueryPropertyBuilderExtensions static SimpleFilterQueryPropertyBuilderExtensions() { s_StringContains = typeof(string).GetMethod(nameof(string.Contains), new[] { typeof(string) }) - ?? throw new Exception("未能找到 string.Contains 方法。"); + ?? throw new Exception("Failed to find string.Contains method."); s_StringStartsWith = typeof(string).GetMethod(nameof(string.StartsWith), new[] { typeof(string) }) - ?? throw new Exception("未能找到 string.StartsWith 方法。"); + ?? throw new Exception("Failed to find string.StartsWith method."); } /// - /// 添加字符串包含篩選條件。 + /// Adds a string contains filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 數據中的篩選鍵選擇器。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The filter query property builder. + /// The filter key selector in the data. + /// The logical operator. + /// The updated filter query property builder. public static SimpleFilterQueryPropertyBuilder HasStringContains( this SimpleFilterQueryPropertyBuilder builder, Expression> filterKeySelector, @@ -39,14 +39,14 @@ public static SimpleFilterQueryPropertyBuilder HasStringC } /// - /// 添加字符串開頭篩選條件。 + /// Adds a string starts-with filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 數據中的篩選鍵選擇器。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The filter query property builder. + /// The filter key selector in the data. + /// The logical operator. + /// The updated filter query property builder. public static SimpleFilterQueryPropertyBuilder HasStringStartsWith( this SimpleFilterQueryPropertyBuilder builder, Expression> filterKeySelector, @@ -57,14 +57,14 @@ public static SimpleFilterQueryPropertyBuilder HasStringS } /// - /// 添加自定義篩選條件。 + /// Adds a custom filter condition. /// - /// 資料型別。 - /// 查詢屬性型別。 - /// 篩選查詢屬性建構器。 - /// 自定義篩選邏輯。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The filter query property builder. + /// The custom filter logic. + /// The logical operator. + /// The updated filter query property builder. public static SimpleFilterQueryPropertyBuilder HasCustomFilter( this SimpleFilterQueryPropertyBuilder builder, Expression> customFilter, @@ -75,15 +75,15 @@ public static SimpleFilterQueryPropertyBuilder HasCustomF } /// - /// 添加字符串篩選條件。 + /// Adds a string filter condition. /// - /// 數據的類型。 - /// 查詢屬性的類型。 - /// 篩選查詢屬性建構器。 - /// 數據中的篩選鍵選擇器。 - /// 字符串方法。 - /// 邏輯運算符。 - /// 更新後的篩選查詢屬性建構器。 + /// The type of the data. + /// The type of the query property. + /// The filter query property builder. + /// The filter key selector in the data. + /// The string method. + /// The logical operator. + /// The updated filter query property builder. [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static SimpleFilterQueryPropertyBuilder AddStringFilter( SimpleFilterQueryPropertyBuilder builder, diff --git a/src/AutoQuery/FilterQueryBuilder.cs b/src/AutoQuery/FilterQueryBuilder.cs index c567799..f4a1b27 100644 --- a/src/AutoQuery/FilterQueryBuilder.cs +++ b/src/AutoQuery/FilterQueryBuilder.cs @@ -6,10 +6,10 @@ namespace AutoQuery; /// -/// 用於構建篩選查詢的建構器類別。 +/// A builder class for constructing filter queries. /// -/// 查詢選項的類型。 -/// 數據的類型。 +/// The type of the query options. +/// The type of the data. public class FilterQueryBuilder { private readonly ConcurrentDictionary _builderProperties = new(); @@ -18,14 +18,14 @@ public class FilterQueryBuilder private readonly Dictionary _queryOptionsProperties = typeof(TQueryOptions).GetProperties().ToDictionary(p => p.Name); /// - /// 註冊一個屬性以用於篩選查詢。 + /// Registers a property for use in filter queries. /// - /// 查詢屬性的類型。 - /// 數據屬性的類型。 - /// 查詢選項中的屬性表達式。 - /// 數據中的篩選鍵選擇器。 - /// 篩選查詢屬性建構器。 - /// 當屬性表達式無效時拋出。 + /// The type of the query property. + /// The type of the data property. + /// The property expression in the query options. + /// The filter key selector in the data. + /// The filter query property builder. + /// Thrown when the property expression is invalid. public ComplexFilterQueryPropertyBuilder Property( Expression> propertyExpression, Expression> filterKeySelector) @@ -40,12 +40,12 @@ public ComplexFilterQueryPropertyBuilder P } /// - /// 註冊一個屬性以用於篩選查詢。 + /// Registers a property for use in filter queries. /// - /// 查詢屬性的類型。 - /// 查詢選項中的屬性表達式。 - /// 篩選查詢屬性建構器。 - /// 當屬性表達式無效時拋出。 + /// The type of the query property. + /// The property expression in the query options. + /// The filter query property builder. + /// Thrown when the property expression is invalid. public SimpleFilterQueryPropertyBuilder Property(Expression> propertyExpression) { var memberPath = propertyExpression.GetMemberPath(firstLevelOnly: true, noError: false); @@ -58,10 +58,10 @@ public SimpleFilterQueryPropertyBuilder Property - /// 構建篩選表達式。 + /// Builds the filter expression. /// - /// 查詢選項的值。 - /// 篩選表達式,如果沒有篩選條件則為 null。 + /// The value of the query options. + /// The filter expression, or null if no filter conditions exist. public Expression>? BuildFilterExpression(TQueryOptions instance) { Expression>? combinedExpression = null; @@ -90,11 +90,11 @@ public SimpleFilterQueryPropertyBuilder Property - /// 使用表達樹取得屬性的值。 + /// Retrieves the value of a property using expression trees. /// - /// 屬性信息。 - /// 查詢選項的實例。 - /// 屬性的值。 + /// The property information. + /// The instance of the query options. + /// The value of the property. private object? GetPropertyValue(PropertyInfo property, TQueryOptions instance) { if (!_propertyAccessorsCache.TryGetValue(property, out var accessor)) @@ -110,13 +110,13 @@ public SimpleFilterQueryPropertyBuilder Property - /// 調用篩選表達式的構建方法。 + /// Invokes the method to build the filter expression. /// - /// 建構器對象。 - /// 篩選屬性的值。 - /// 查詢屬性的類型。 - /// 篩選表達式。 - /// 當找不到 BuildFilterExpression 方法時拋出。 + /// The builder object. + /// The value of the filter property. + /// The type of the query property. + /// The filter expression. + /// Thrown when the BuildFilterExpression method is not found. private Expression>? InvokeBuildFilterExpression(object builderObj, object filterPropertyValue, Type queryPropertyType) { var builderType = builderObj.GetType(); @@ -145,11 +145,11 @@ public SimpleFilterQueryPropertyBuilder Property - /// 合併兩個篩選表達式。 + /// Combines two filter expressions. /// - /// 第一個篩選表達式。 - /// 第二個篩選表達式。 - /// 合併後的篩選表達式。 + /// The first filter expression. + /// The second filter expression. + /// The combined filter expression. private static Expression> CombineExpressions(Expression> expr1, Expression> expr2) { var parameter = Expression.Parameter(typeof(TData)); @@ -159,4 +159,4 @@ private static Expression> CombineExpressions(Expression>(body, parameter); } -} \ No newline at end of file +} diff --git a/src/AutoQuery/LogicalOperator.cs b/src/AutoQuery/LogicalOperator.cs index 1611083..812e88d 100644 --- a/src/AutoQuery/LogicalOperator.cs +++ b/src/AutoQuery/LogicalOperator.cs @@ -1,17 +1,17 @@ namespace AutoQuery; /// -/// 表示可以在查詢中使用的邏輯運算符。 +/// Represents logical operators that can be used in queries. /// public enum LogicalOperator { /// - /// 邏輯 AND 運算符。 + /// Logical AND operator. /// AND, /// - /// 邏輯 OR 運算符。 + /// Logical OR operator. /// OR } diff --git a/src/AutoQuery/PagedResult.cs b/src/AutoQuery/PagedResult.cs index 65f7392..e4bd3ec 100644 --- a/src/AutoQuery/PagedResult.cs +++ b/src/AutoQuery/PagedResult.cs @@ -1,11 +1,11 @@ namespace AutoQuery; /// -/// 表示分頁結果的泛型記錄類型。 +/// Represents a generic record type for paginated results. /// -/// 結果集中包含的數據類型。 -/// 分頁結果的數據集合,使用 表示。 -/// 當前頁碼(從 1 開始)。 -/// 總頁數。 -/// 結果集中數據的總數量。 -public record PagedResult(IQueryable Datas, int Page, int TotalPages, int Count); \ No newline at end of file +/// The type of data contained in the result set. +/// The data collection of the paginated result, represented as . +/// The current page number (starting from 1). +/// The total number of pages. +/// The total number of data items in the result set. +public record PagedResult(IQueryable Datas, int Page, int TotalPages, int Count); diff --git a/src/AutoQuery/QueryProcessor.cs b/src/AutoQuery/QueryProcessor.cs index 9b79b1a..e983e48 100644 --- a/src/AutoQuery/QueryProcessor.cs +++ b/src/AutoQuery/QueryProcessor.cs @@ -6,7 +6,7 @@ namespace AutoQuery; /// -/// 提供查詢處理服務。 +/// Provides query processing services. /// public class QueryProcessor : IQueryProcessor { @@ -53,11 +53,11 @@ public class QueryProcessor : IQueryProcessor } /// - /// 獲取篩選查詢建構器。 + /// Gets the filter query builder. /// - /// 查詢選項的類型。 - /// 數據的類型。 - /// 篩選查詢建構器,如果不存在則為 null。 + /// The type of the query options. + /// The type of the data. + /// The filter query builder, or null if it does not exist. private FilterQueryBuilder? GetFilterQueryBuilder() { var key = (typeof(TQueryOptions), typeof(TData)); @@ -68,11 +68,11 @@ public class QueryProcessor : IQueryProcessor } /// - /// 添加篩選查詢建構器。 + /// Adds a filter query builder. /// - /// 查詢選項的類型。 - /// 數據的類型。 - /// 篩選查詢建構器。 + /// The type of the query options. + /// The type of the data. + /// The filter query builder. public void AddFilterQueryBuilder(FilterQueryBuilder builder) { var key = (typeof(TQueryOptions), typeof(TData)); @@ -80,9 +80,9 @@ public void AddFilterQueryBuilder(FilterQueryBuilder - /// 從指定的程序集應用配置。 + /// Applies configurations from the specified assembly. /// - /// 程序集。 + /// The assembly. public void ApplyConfigurationsFromAssembly(Assembly assembly) { var configurations = assembly.GetTypes() diff --git a/src/AutoQuery/SimpleFilterQueryPropertyBuilder.cs b/src/AutoQuery/SimpleFilterQueryPropertyBuilder.cs index 1fc259a..0306754 100644 --- a/src/AutoQuery/SimpleFilterQueryPropertyBuilder.cs +++ b/src/AutoQuery/SimpleFilterQueryPropertyBuilder.cs @@ -5,19 +5,19 @@ namespace AutoQuery; /// -/// 用於構建自定義篩選查詢屬性的建構器類別。 +/// A builder class for constructing custom filter query properties. /// -/// 數據的類型。 -/// 查詢屬性的類型。 +/// The type of the data. +/// The type of the query property. public class SimpleFilterQueryPropertyBuilder : IFilterExpressionBuilder { private List<(Expression> Expression, LogicalOperator Logical)> _filterExpressions = new(); /// - /// 添加自定義篩選表達式。 + /// Adds a custom filter expression. /// - /// 篩選表達式。 - /// 邏輯運算符。 + /// The filter expression. + /// The logical operator. public void AddFilterExpression(Expression> filterExpression, LogicalOperator logicalOperator) { _filterExpressions.Add((filterExpression, logicalOperator)); @@ -44,4 +44,4 @@ public Expression> BuildFilterExpression(TQueryProperty filter return Expression.Lambda>(finalExpression ?? Expression.Constant(true), parameter); } -} \ No newline at end of file +}