1313namespace AutoQuery . AspNetCore ;
1414
1515/// <summary>
16- /// 字段投影屬性,用於在返回結果中僅包含指定的字段。
16+ /// Field projection attribute used to include only specified fields in the returned result.
1717/// </summary>
1818public class EnableFieldProjectionAttribute : ActionFilterAttribute
1919{
@@ -24,18 +24,18 @@ public class EnableFieldProjectionAttribute : ActionFilterAttribute
2424 private IQueryOptions ? _queryOptions ;
2525
2626 /// <summary>
27- /// 在操作執行之前調用,從操作參數中提取 QueryOptions。
27+ /// Called before the action is executed to extract QueryOptions from the action parameters.
2828 /// </summary>
29- /// <param name="context">操作執行上下文。 </param>
29+ /// <param name="context">The action execution context. </param>
3030 public override void OnActionExecuting ( ActionExecutingContext context )
3131 {
3232 _queryOptions = ExtractQueryOptions ( context ) ;
3333 }
3434
3535 /// <summary>
36- /// 在操作執行之後調用,根據指定的字段過濾返回結果。
36+ /// Called after the action is executed to filter the returned result based on the specified fields.
3737 /// </summary>
38- /// <param name="context">操作執行上下文。 </param>
38+ /// <param name="context">The action execution context. </param>
3939 public override void OnActionExecuted ( ActionExecutedContext context )
4040 {
4141 if ( _queryOptions == null || string . IsNullOrEmpty ( _queryOptions . Fields ) )
@@ -53,12 +53,12 @@ public override void OnActionExecuted(ActionExecutedContext context)
5353 }
5454
5555 /// <summary>
56- /// 過濾結果,僅包含選擇的字段。
56+ /// Filters the result to include only the selected fields.
5757 /// </summary>
58- /// <param name="value">要過濾的對象。 </param>
59- /// <param name="selectedFields">選擇的字段集合。 </param>
60- /// <param name="serializerOptions">JSON 序列化選項。 </param>
61- /// <returns>過濾後的對象。 </returns>
58+ /// <param name="value">The object to filter. </param>
59+ /// <param name="selectedFields">The set of selected fields. </param>
60+ /// <param name="serializerOptions">JSON serialization options. </param>
61+ /// <returns>The filtered object. </returns>
6262 private static object FilterResult ( object value , HashSet < string > selectedFields , JsonSerializerOptions serializerOptions )
6363 {
6464 if ( value is IEnumerable < object > enumerable )
@@ -76,12 +76,12 @@ private static object FilterResult(object value, HashSet<string> selectedFields,
7676 }
7777
7878 /// <summary>
79- /// 過濾集合類型的結果。
79+ /// Filters a collection-type result.
8080 /// </summary>
81- /// <param name="enumerable">要過濾的集合。 </param>
82- /// <param name="selectedFields">選擇的字段集合。 </param>
83- /// <param name="serializerOptions">JSON 序列化選項。 </param>
84- /// <returns>過濾後的集合。 </returns>
81+ /// <param name="enumerable">The collection to filter. </param>
82+ /// <param name="selectedFields">The set of selected fields. </param>
83+ /// <param name="serializerOptions">JSON serialization options. </param>
84+ /// <returns>The filtered collection. </returns>
8585 private static List < Dictionary < string , object ? > > FilterEnumerable ( IEnumerable < object > enumerable , HashSet < string > selectedFields , JsonSerializerOptions serializerOptions )
8686 {
8787 var result = new List < Dictionary < string , object ? > > ( ) ;
@@ -94,13 +94,13 @@ private static object FilterResult(object value, HashSet<string> selectedFields,
9494 }
9595
9696 /// <summary>
97- /// 過濾單個物件的結果。
97+ /// Filters the result of a single object.
9898 /// </summary>
99- /// <param name="value">要過濾的物件。 </param>
100- /// <param name="selectedFields">選擇的字段集合。 </param>
101- /// <param name="serializerOptions">JSON 序列化選項。 </param>
102- /// <param name="firstLevelOnly">是否僅過濾第一層屬性。 </param>
103- /// <returns>過濾後的字典。 </returns>
99+ /// <param name="value">The object to filter. </param>
100+ /// <param name="selectedFields">The set of selected fields. </param>
101+ /// <param name="serializerOptions">JSON serialization options. </param>
102+ /// <param name="firstLevelOnly">Whether to filter only the first-level properties. </param>
103+ /// <returns>The filtered dictionary. </returns>
104104 private static Dictionary < string , object ? > FilterObject ( object value , HashSet < string > selectedFields , JsonSerializerOptions serializerOptions , bool firstLevelOnly = false )
105105 {
106106 var result = new Dictionary < string , object ? > ( ) ;
@@ -138,20 +138,20 @@ private static object FilterResult(object value, HashSet<string> selectedFields,
138138 }
139139
140140 /// <summary>
141- /// 從操作上下文中提取 QueryOptions。
141+ /// Extracts QueryOptions from the action context.
142142 /// </summary>
143- /// <param name="context">操作執行上下文。 </param>
144- /// <returns>提取的 QueryOptions。 </returns>
143+ /// <param name="context">The action execution context. </param>
144+ /// <returns>The extracted QueryOptions. </returns>
145145 private static IQueryOptions ? ExtractQueryOptions ( ActionExecutingContext context )
146146 {
147147 return context . ActionArguments . Values . OfType < IQueryOptions > ( ) . FirstOrDefault ( ) ;
148148 }
149149
150150 /// <summary>
151- /// 解析選擇的字段。
151+ /// Parses the selected fields.
152152 /// </summary>
153- /// <param name="fields">逗號分隔的字段名稱。 </param>
154- /// <returns>選擇的字段集合。 </returns>
153+ /// <param name="fields">Comma-separated field names. </param>
154+ /// <returns>The set of selected fields. </returns>
155155 private static HashSet < string > ParseSelectedFields ( string fields )
156156 {
157157 return fields . Split ( ',' )
@@ -160,21 +160,21 @@ private static HashSet<string> ParseSelectedFields(string fields)
160160 }
161161
162162 /// <summary>
163- /// 獲取 JSON 序列化選項。
163+ /// Gets the JSON serialization options.
164164 /// </summary>
165- /// <param name="context">操作執行上下文。 </param>
166- /// <returns>JSON 序列化選項。 </returns>
165+ /// <param name="context">The action execution context. </param>
166+ /// <returns>The JSON serialization options. </returns>
167167 private static JsonSerializerOptions GetSerializerOptions ( ActionExecutedContext context )
168168 {
169169 return context . HttpContext . RequestServices . GetRequiredService < IOptions < JsonOptions > > ( ) . Value . JsonSerializerOptions ;
170170 }
171171
172172 /// <summary>
173- /// 使用表達樹取得屬性的值。
173+ /// Gets the value of a property using expression trees.
174174 /// </summary>
175- /// <param name="property">屬性信息。 </param>
176- /// <param name="instance">對象實例。 </param>
177- /// <returns>屬性的值。 </returns>
175+ /// <param name="property">The property information. </param>
176+ /// <param name="instance">The object instance. </param>
177+ /// <returns>The value of the property. </returns>
178178 private static object ? GetPropertyValue ( PropertyInfo property , object instance )
179179 {
180180 if ( ! _propertyAccessorsCache . TryGetValue ( property , out var accessor ) )
@@ -191,11 +191,11 @@ private static JsonSerializerOptions GetSerializerOptions(ActionExecutedContext
191191 }
192192
193193 /// <summary>
194- /// 獲取屬性的 JSON 屬性名稱。
194+ /// Gets the JSON property name of a property.
195195 /// </summary>
196- /// <param name="propInfo">屬性信息。 </param>
197- /// <param name="serializerOptions">JSON 序列化選項。 </param>
198- /// <returns>屬性的 JSON 名稱。 </returns>
196+ /// <param name="propInfo">The property information. </param>
197+ /// <param name="serializerOptions">JSON serialization options. </param>
198+ /// <returns>The JSON name of the property. </returns>
199199 private static string GetJsonPropertyName ( PropertyInfo propInfo , JsonSerializerOptions serializerOptions )
200200 {
201201 var jsonPropertyNameAttr = _jsonPropertyNameCache [ propInfo ] ;
@@ -205,9 +205,9 @@ private static string GetJsonPropertyName(PropertyInfo propInfo, JsonSerializerO
205205 }
206206
207207 /// <summary>
208- /// 緩存類型的屬性信息。
208+ /// Caches the property information of a type.
209209 /// </summary>
210- /// <param name="type">要緩存的類型。 </param>
210+ /// <param name="type">The type to cache. </param>
211211 private static void CacheProperties ( Type type )
212212 {
213213 if ( ! _propertyInfoCache . ContainsKey ( type ) )
@@ -224,10 +224,10 @@ private static void CacheProperties(Type type)
224224 }
225225
226226 /// <summary>
227- /// 確定狀態碼是否表示成功。
227+ /// Determines whether the status code indicates success.
228228 /// </summary>
229- /// <param name="statusCode">HTTP 狀態碼。 </param>
230- /// <returns>如果狀態碼表示成功,則為 true;否則為 false。 </returns>
229+ /// <param name="statusCode">The HTTP status code. </param>
230+ /// <returns>True if the status code indicates success; otherwise, false. </returns>
231231 private static bool IsSuccessStatusCode ( int statusCode )
232232 {
233233 return statusCode >= 200 && statusCode < 300 ;
0 commit comments