Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
/MvcPublic archive

Commit8eb6327

Browse files
committed
Make HTML helper parameter names consistent
-#944- name `string` expression name and `Expression<Func<TModel, TResult>>` parameters "expression" - single special case is `GenerateIdFromName(string fullName)` since every other expression name is relative to the current `ViewData,TemplateInfo.HtmlFieldPrefix` value - applied from `IHtmlHelper` and `IHtmlGenerator` on up- name `IHtmlHelper` and `IHtmlHelper<TModel>` parameters "htmlHelper"- rename `TProperty` and `TValue` type parameters to `TResult`nits:- clean up abbreviated names in `CachedExpressionCompiler`- change `ObjectToDictionary()`'s parameter name to `value`- use `nameof` more to make renaming (and refactoring) easier in the future- rewrap parameters and arguments to avoid long lines and orphans
1 parentf19c2e4 commit8eb6327

File tree

27 files changed

+1261
-1003
lines changed

27 files changed

+1261
-1003
lines changed

‎samples/MvcSample.Web/Views/Shared/EditorTemplates/Decimal.cshtml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
}
1414

1515
@Html.TextBox(
16-
name: null,
16+
expression: null,
1717
value: FormattedValue,
1818
htmlAttributes: new{@class="text-box single-line",style="font-weight: bold",})

‎src/Microsoft.AspNet.Mvc.Core/Rendering/Expressions/CachedExpressionCompiler.cs‎

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,56 @@ public static class CachedExpressionCompiler
1515
// relying on cache lookups and other techniques to save time if appropriate.
1616
// If the provided expression is particularly obscure and the system doesn't know
1717
// how to handle it, we'll just compile the expression as normal.
18-
publicstaticFunc<TModel,TValue>Process<TModel,TValue>(
19-
[NotNull]Expression<Func<TModel,TValue>>lambdaExpression)
18+
publicstaticFunc<TModel,TResult>Process<TModel,TResult>(
19+
[NotNull]Expression<Func<TModel,TResult>>expression)
2020
{
21-
returnCompiler<TModel,TValue>.Compile(lambdaExpression);
21+
returnCompiler<TModel,TResult>.Compile(expression);
2222
}
2323

24-
privatestaticclassCompiler<TIn,TOut>
24+
privatestaticclassCompiler<TModel,TResult>
2525
{
26-
privatestaticFunc<TIn,TOut>_identityFunc;
26+
privatestaticFunc<TModel,TResult>_identityFunc;
2727

28-
privatestaticreadonlyConcurrentDictionary<MemberInfo,Func<TIn,TOut>>_simpleMemberAccessDict=
29-
newConcurrentDictionary<MemberInfo,Func<TIn,TOut>>();
28+
privatestaticreadonlyConcurrentDictionary<MemberInfo,Func<TModel,TResult>>_simpleMemberAccessDict=
29+
newConcurrentDictionary<MemberInfo,Func<TModel,TResult>>();
3030

31-
privatestaticreadonlyConcurrentDictionary<MemberInfo,Func<object,TOut>>_constMemberAccessDict=
32-
newConcurrentDictionary<MemberInfo,Func<object,TOut>>();
31+
privatestaticreadonlyConcurrentDictionary<MemberInfo,Func<object,TResult>>_constMemberAccessDict=
32+
newConcurrentDictionary<MemberInfo,Func<object,TResult>>();
3333

34-
publicstaticFunc<TIn,TOut>Compile([NotNull]Expression<Func<TIn,TOut>>expr)
34+
publicstaticFunc<TModel,TResult>Compile([NotNull]Expression<Func<TModel,TResult>>expression)
3535
{
36-
returnCompileFromIdentityFunc(expr)
37-
??CompileFromConstLookup(expr)
38-
??CompileFromMemberAccess(expr)
39-
??CompileSlow(expr);
36+
returnCompileFromIdentityFunc(expression)
37+
??CompileFromConstLookup(expression)
38+
??CompileFromMemberAccess(expression)
39+
??CompileSlow(expression);
4040
}
4141

42-
privatestaticFunc<TIn,TOut>CompileFromConstLookup([NotNull]Expression<Func<TIn,TOut>>expr)
42+
privatestaticFunc<TModel,TResult>CompileFromConstLookup(
43+
[NotNull]Expression<Func<TModel,TResult>>expression)
4344
{
44-
varconstExpr=expr.BodyasConstantExpression;
45-
if(constExpr!=null)
45+
varconstantExpression=expression.BodyasConstantExpression;
46+
if(constantExpression!=null)
4647
{
4748
// model => {const}
4849

49-
varconstantValue=(TOut)constExpr.Value;
50+
varconstantValue=(TResult)constantExpression.Value;
5051
return _=>constantValue;
5152
}
5253

5354
returnnull;
5455
}
5556

56-
privatestaticFunc<TIn,TOut>CompileFromIdentityFunc([NotNull]Expression<Func<TIn,TOut>>expr)
57+
privatestaticFunc<TModel,TResult>CompileFromIdentityFunc(
58+
[NotNull]Expression<Func<TModel,TResult>>expression)
5759
{
58-
if(expr.Body==expr.Parameters[0])
60+
if(expression.Body==expression.Parameters[0])
5961
{
6062
// model => model
6163

6264
// Don't need to lock, as all identity funcs are identical.
6365
if(_identityFunc==null)
6466
{
65-
_identityFunc=expr.Compile();
67+
_identityFunc=expression.Compile();
6668
}
6769

6870
return_identityFunc;
@@ -71,50 +73,52 @@ private static Func<TIn, TOut> CompileFromIdentityFunc([NotNull] Expression<Func
7173
returnnull;
7274
}
7375

74-
privatestaticFunc<TIn,TOut>CompileFromMemberAccess([NotNull]Expression<Func<TIn,TOut>>expr)
76+
privatestaticFunc<TModel,TResult>CompileFromMemberAccess(
77+
[NotNull]Expression<Func<TModel,TResult>>expression)
7578
{
7679
// Performance tests show that on the x64 platform, special-casing static member and
7780
// captured local variable accesses is faster than letting the fingerprinting system
7881
// handle them. On the x86 platform, the fingerprinting system is faster, but only
7982
// by around one microsecond, so it's not worth it to complicate the logic here with
8083
// an architecture check.
8184

82-
varmemberExpr=expr.BodyasMemberExpression;
83-
if(memberExpr!=null)
85+
varmemberExpression=expression.BodyasMemberExpression;
86+
if(memberExpression!=null)
8487
{
85-
if(memberExpr.Expression==expr.Parameters[0]||memberExpr.Expression==null)
88+
if(memberExpression.Expression==expression.Parameters[0]||memberExpression.Expression==null)
8689
{
8790
// model => model.Member or model => StaticMember
88-
return_simpleMemberAccessDict.GetOrAdd(memberExpr.Member, _=>expr.Compile());
91+
return_simpleMemberAccessDict.GetOrAdd(memberExpression.Member, _=>expression.Compile());
8992
}
9093

91-
varconstExpr=memberExpr.ExpressionasConstantExpression;
92-
if(constExpr!=null)
94+
varconstantExpression=memberExpression.ExpressionasConstantExpression;
95+
if(constantExpression!=null)
9396
{
9497
// model => {const}.Member (captured local variable)
95-
vardel=_constMemberAccessDict.GetOrAdd(memberExpr.Member, _=>
98+
varcompiledExpression=_constMemberAccessDict.GetOrAdd(memberExpression.Member, _=>
9699
{
97100
// rewrite as capturedLocal => ((TDeclaringType)capturedLocal).Member
98-
varconstParamExpr=Expression.Parameter(typeof(object),"capturedLocal");
99-
varconstCastExpr=Expression.Convert(constParamExpr,memberExpr.Member.DeclaringType);
100-
varnewMemberAccessExpr=memberExpr.Update(constCastExpr);
101-
varnewLambdaExpr=
102-
Expression.Lambda<Func<object,TOut>>(newMemberAccessExpr,constParamExpr);
103-
returnnewLambdaExpr.Compile();
101+
varparameterExpression=Expression.Parameter(typeof(object),"capturedLocal");
102+
varcastExpression=
103+
Expression.Convert(parameterExpression,memberExpression.Member.DeclaringType);
104+
varnewMemberExpression=memberExpression.Update(castExpression);
105+
varnewExpression=
106+
Expression.Lambda<Func<object,TResult>>(newMemberExpression,parameterExpression);
107+
returnnewExpression.Compile();
104108
});
105109

106-
varcapturedLocal=constExpr.Value;
107-
return _=>del(capturedLocal);
110+
varcapturedLocal=constantExpression.Value;
111+
return _=>compiledExpression(capturedLocal);
108112
}
109113
}
110114

111115
returnnull;
112116
}
113117

114-
privatestaticFunc<TIn,TOut>CompileSlow([NotNull]Expression<Func<TIn,TOut>>expr)
118+
privatestaticFunc<TModel,TResult>CompileSlow([NotNull]Expression<Func<TModel,TResult>>expression)
115119
{
116120
// fallback compilation system - just compile the expression directly
117-
returnexpr.Compile();
121+
returnexpression.Compile();
118122
}
119123
}
120124
}

‎src/Microsoft.AspNet.Mvc.Core/Rendering/Expressions/ExpressionHelper.cs‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ public static class ExpressionHelper
1616
publicstaticstringGetExpressionText(stringexpression)
1717
{
1818
// If it's exactly "model", then give them an empty string, to replicate the lambda behavior.
19-
return
20-
string.Equals(expression,"model",StringComparison.OrdinalIgnoreCase)
21-
?string.Empty
22-
:expression;
19+
returnstring.Equals(expression,"model",StringComparison.OrdinalIgnoreCase)?string.Empty:expression;
2320
}
2421

2522
publicstaticstringGetExpressionText([NotNull]LambdaExpressionexpression)
@@ -91,7 +88,8 @@ public static string GetExpressionText([NotNull] LambdaExpression expression)
9188
returnstring.Empty;
9289
}
9390

94-
privatestaticstringGetIndexerInvocation([NotNull]Expressionexpression,
91+
privatestaticstringGetIndexerInvocation(
92+
[NotNull]Expressionexpression,
9593
[NotNull]ParameterExpression[]parameters)
9694
{
9795
varconverted=Expression.Convert(expression,typeof(object));

‎src/Microsoft.AspNet.Mvc.Core/Rendering/Expressions/ExpressionMetadataProvider.cs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
usingSystem;
5-
usingSystem.Linq;
65
usingSystem.Linq.Expressions;
76
usingSystem.Reflection;
87
usingMicrosoft.AspNet.Mvc.Core;
@@ -12,9 +11,9 @@ namespace Microsoft.AspNet.Mvc.Rendering.Expressions
1211
{
1312
publicstaticclassExpressionMetadataProvider
1413
{
15-
publicstaticModelMetadataFromLambdaExpression<TParameter,TValue>(
16-
[NotNull]Expression<Func<TParameter,TValue>>expression,
17-
[NotNull]ViewDataDictionary<TParameter>viewData,
14+
publicstaticModelMetadataFromLambdaExpression<TModel,TResult>(
15+
[NotNull]Expression<Func<TModel,TResult>>expression,
16+
[NotNull]ViewDataDictionary<TModel>viewData,
1817
IModelMetadataProvidermetadataProvider)
1918
{
2019
stringpropertyName=null;
@@ -70,7 +69,7 @@ public static ModelMetadata FromLambdaExpression<TParameter, TValue>(
7069

7170
returnGetMetadataFromProvider(
7271
modelAccessor,
73-
typeof(TValue),
72+
typeof(TResult),
7473
propertyName,
7574
container,
7675
containerType,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp