當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。