本文整理汇总了C#中System.Linq.Expressions.Expression.GetMember方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.GetMember方法的具体用法?C# Expression.GetMember怎么用?C# Expression.GetMember使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Linq.Expressions.Expression
的用法示例。
在下文中一共展示了Expression.GetMember方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateFromExpression
/// <summary>
/// Creates an IErrorMessageSource from an expression: () => MyResources.SomeResourceName
/// </summary>
/// <param name="expression">The expression </param>
/// <param name="resourceProviderSelectionStrategy">Strategy used to construct the resource accessor</param>
/// <returns>Error message source</returns>
public static IStringSource CreateFromExpression(Expression<Func<string>> expression, IResourceAccessorBuilder resourceProviderSelectionStrategy) {
var constant = expression.Body as ConstantExpression;
if (constant != null) {
return new StaticStringSource((string)constant.Value);
}
var member = expression.GetMember();
if (member == null) {
throw new InvalidOperationException("Only MemberExpressions an be passed to BuildResourceAccessor, eg () => Messages.MyResource");
}
var resourceType = member.DeclaringType;
var resourceName = member.Name;
return new LocalizedStringSource(resourceType, resourceName, resourceProviderSelectionStrategy);
}
示例2: BuildResourceAccessor
public static ResourceMetaData BuildResourceAccessor(Expression<Func<string>> expression)
{
var constant = expression.Body as ConstantExpression;
if(constant != null) {
return new ResourceMetaData(null,null, () => (string)constant.Value);
}
var member = expression.GetMember();
if(member == null) {
throw new InvalidOperationException("Only MemberExpressions an be passed to BuildResourceAccessor, eg () => Messages.MyResource");
}
var resourceType = member.DeclaringType;
var resourceName = member.Name;
return BuildResourceAccessor(resourceName, resourceType);
}
示例3: GetClientRules
private IEnumerable<ModelClientValidationRule> GetClientRules(Expression<Func<TestModel, object>> expression )
{
var propertyName = expression.GetMember().Name;
var metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(TestModel), propertyName);
var factory = new Mock<IValidatorFactory>();
factory.Setup(x => x.GetValidator(typeof(TestModel))).Returns(validator);
var provider = new FluentValidationModelValidatorProvider(factory.Object);
var propertyValidators = provider.GetValidators(metadata, controllerContext);
return (propertyValidators.SelectMany(x => x.GetClientValidationRules())).ToList();
}
示例4: GetClientRule
private ModelClientValidationRule GetClientRule(Expression<Func<TestModel, object>> expression)
{
var propertyName = expression.GetMember().Name;
var metadata = new DataAnnotationsModelMetadataProvider().GetMetadataForProperty(null, typeof(TestModel), propertyName);
var factory = new Mock<IValidatorFactory>();
factory.Setup(x => x.GetValidator(typeof(TestModel))).Returns(validator);
var provider = new FluentValidationModelValidatorProvider(factory.Object);
var propertyValidator = provider.GetValidators(metadata, controllerContext).Single();
var clientRule = propertyValidator.GetClientValidationRules().Single();
return clientRule;
}