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);
|
return GetMetadataFromProvider(modelAccessor, typeof(TValue), propertyName, containerType, metadataProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ModelMetadata FromStringExpression([NotNull] string expression,
|
public static ModelMetadata FromStringExpression(string expression,
|
||||||
[NotNull] ViewDataDictionary viewData,
|
[NotNull] ViewDataDictionary viewData,
|
||||||
IModelMetadataProvider metadataProvider)
|
IModelMetadataProvider metadataProvider)
|
||||||
{
|
{
|
||||||
|
if(string.IsNullOrEmpty(expression))
|
||||||
|
{
|
||||||
|
return viewData.ModelMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
if (expression.Length == 0)
|
if (expression.Length == 0)
|
||||||
{
|
{
|
||||||
// Empty string really means "model metadata for the current model"
|
// Empty string really means "model metadata for the current model"
|
||||||
|
|
|
||||||
|
|
@ -254,13 +254,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public HtmlString DisplayName(string expression)
|
public HtmlString DisplayName(string expression)
|
||||||
{
|
{
|
||||||
var modelMetadata = string.IsNullOrEmpty(expression) ?
|
var metadata = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);
|
||||||
ViewData.ModelMetadata :
|
return GenerateDisplayName(metadata, expression);
|
||||||
ExpressionMetadataProvider.FromStringExpression(
|
|
||||||
expression,
|
|
||||||
ViewData,
|
|
||||||
MetadataProvider);
|
|
||||||
return GenerateDisplayName(modelMetadata, expression);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -299,14 +294,9 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public HtmlString Label(string expression, string labelText, object htmlAttributes)
|
public HtmlString Label(string expression, string labelText, object htmlAttributes)
|
||||||
{
|
{
|
||||||
var modelMetadata = string.IsNullOrEmpty(expression)?
|
var metadata = ExpressionMetadataProvider.FromStringExpression(expression, ViewData, MetadataProvider);
|
||||||
ViewData.ModelMetadata :
|
|
||||||
ExpressionMetadataProvider.FromStringExpression(
|
|
||||||
expression,
|
|
||||||
ViewData,
|
|
||||||
MetadataProvider);
|
|
||||||
return GenerateLabel(
|
return GenerateLabel(
|
||||||
modelMetadata,
|
metadata,
|
||||||
expression,
|
expression,
|
||||||
labelText,
|
labelText,
|
||||||
htmlAttributes);
|
htmlAttributes);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue