当前位置: 首页>>代码示例>>C#>>正文


C# Expression.GetMember方法代码示例

本文整理汇总了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);
        }
开发者ID:vebin,项目名称:soa,代码行数:23,代码来源:LocalizedStringSource.cs

示例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);
        }
开发者ID:Tigraine,项目名称:FluentValidation,代码行数:19,代码来源:ResourceHelper.cs

示例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();
        }
开发者ID:schotime,项目名称:FluentValidation,代码行数:13,代码来源:ClientsideMessageTester.cs

示例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;
        }
开发者ID:schotime,项目名称:FluentValidation,代码行数:14,代码来源:ClientsideMessageTester.cs


注:本文中的System.Linq.Expressions.Expression.GetMember方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。