Cleaning up sprinkled null checks and adding it to a centralized place - FromStringExpression
This commit is contained in:
parent
488ec2f52e
commit
e0592d01af
|
|
@ -69,10 +69,15 @@ namespace Microsoft.AspNet.Mvc.Rendering.Expressions
|
|||
return GetMetadataFromProvider(modelAccessor, typeof(TValue), propertyName, containerType, metadataProvider);
|
||||
}
|
||||
|
||||
public static ModelMetadata FromStringExpression([NotNull] string expression,
|
||||
public static ModelMetadata FromStringExpression(string expression,
|
||||
[NotNull] ViewDataDictionary viewData,
|
||||
IModelMetadataProvider metadataProvider)
|
||||
{
|
||||
if(string.IsNullOrEmpty(expression))
|
||||
{
|
||||
return viewData.ModelMetadata;
|
||||
}
|
||||
|
||||
if (expression.Length == 0)
|
||||
{
|
||||
// Empty string really means "model metadata for the current model"
|
||||
|
|
|
|||
|
|
@ -254,13 +254,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
/// <inheritdoc />
|
||||
public HtmlString DisplayName(string expression)
|
||||
{
|
||||
var modelMetadata = string.IsNullOrEmpty(expression) ?
|
||||
ViewData.ModelMetadata :
|
||||
ExpressionMetadataProvider.FromStringExpression(
|
||||
expression,
|
||||
ViewData,
|
||||
MetadataProvider);
|
||||
return GenerateDisplayName(modelMetadata, expression);
|
||||
var metadata = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);
|
||||
return GenerateDisplayName(metadata, expression);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -299,14 +294,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
/// <inheritdoc />
|
||||
public HtmlString Label(string expression, string labelText, object htmlAttributes)
|
||||
{
|
||||
var modelMetadata = string.IsNullOrEmpty(expression)?
|
||||
ViewData.ModelMetadata :
|
||||
ExpressionMetadataProvider.FromStringExpression(
|
||||
expression,
|
||||
ViewData,
|
||||
MetadataProvider);
|
||||
var metadata = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);
|
||||
return GenerateLabel(
|
||||
modelMetadata,
|
||||
metadata,
|
||||
expression,
|
||||
labelText,
|
||||
htmlAttributes);
|
||||
|
|
|
|||
Loading…
Reference in New Issue