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


C# ModelMetadata.GetDisplayName方法代码示例

本文整理汇总了C#中System.Web.Http.Metadata.ModelMetadata.GetDisplayName方法的典型用法代码示例。如果您正苦于以下问题:C# ModelMetadata.GetDisplayName方法的具体用法?C# ModelMetadata.GetDisplayName怎么用?C# ModelMetadata.GetDisplayName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Http.Metadata.ModelMetadata的用法示例。


在下文中一共展示了ModelMetadata.GetDisplayName方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Validate

        public override IEnumerable<ModelValidationResult> Validate(ModelMetadata metadata, object container)
        {
            // Per the WCF RIA Services team, instance can never be null (if you have
            // no parent, you pass yourself for the "instance" parameter).
            ValidationContext context = new ValidationContext(container ?? metadata.Model, null, null);
            context.DisplayName = metadata.GetDisplayName();

            ValidationResult result = Attribute.GetValidationResult(metadata.Model, context);

            if (result != ValidationResult.Success)
            {
                return new ModelValidationResult[] { new ModelValidationResult { Message = result.ErrorMessage } };
            }

            return new ModelValidationResult[0];
        }
开发者ID:chrissimon-au,项目名称:aspnetwebstack,代码行数:16,代码来源:DataAnnotationsModelValidator.cs

示例2: Validate

        public override IEnumerable<ModelValidationResult> Validate(ModelMetadata metadata, object container)
        {
            // Per the WCF RIA Services team, instance can never be null (if you have
            // no parent, you pass yourself for the "instance" parameter).
            
            string memberName = metadata.GetDisplayName();
            ValidationContext context = new ValidationContext(container ?? metadata.Model)
            {
                DisplayName = memberName,
                MemberName = memberName
            };

            ValidationResult result = Attribute.GetValidationResult(metadata.Model, context);

            if (result != ValidationResult.Success)
            {
                // ModelValidationResult.MemberName is used by invoking validators (such as ModelValidationNode) to 
                // construct the ModelKey for ModelStateDictionary. When validating at type level we want to append the 
                // returned MemberNames if specified (e.g. person.Address.FirstName). For property validation, the 
                // ModelKey can be constructed using the ModelMetadata and we should ignore MemberName (we don't want 
                // (person.Name.Name). However the invoking validator does not have a way to distinguish between these two 
                // cases. Consequently we'll only set MemberName if this validation returns a MemberName that is different
                // from the property being validated.

                string errorMemberName = result.MemberNames.FirstOrDefault();
                if (String.Equals(errorMemberName, memberName, StringComparison.Ordinal))
                {
                    errorMemberName = null;
                }

                var validationResult = new ModelValidationResult
                {
                    Message = result.ErrorMessage,
                    MemberName = errorMemberName
                };
                
                return new ModelValidationResult[] { validationResult };
            }

            return Enumerable.Empty<ModelValidationResult>();
        }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:41,代码来源:DataAnnotationsModelValidator.cs

示例3: GetResourceCommon

 private static string GetResourceCommon(HttpActionContext actionContext, ModelMetadata modelMetadata, object incomingValue, Func<HttpActionContext, string> resourceAccessor)
 {
     string displayName = modelMetadata.GetDisplayName();
     string errorMessageTemplate = resourceAccessor(actionContext);
     return Error.Format(errorMessageTemplate, incomingValue, displayName);
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:6,代码来源:ModelBinderConfig.cs

示例4: ReturnsTypeNameWhenPropertyNameAndDisplayNameAreNull

        public void ReturnsTypeNameWhenPropertyNameAndDisplayNameAreNull()
        {
            // Arrange
            Mock<ModelMetadataProvider> provider = new Mock<ModelMetadataProvider>();
            ModelMetadata metadata = new ModelMetadata(provider.Object, null, null, typeof(object), null);

            // Act
            string result = metadata.GetDisplayName();

            // Assert
            Assert.Equal("Object", result);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:12,代码来源:ModelMetadataTest.cs

示例5: ReturnsDisplayNameWhenSet

        public void ReturnsDisplayNameWhenSet()
        {
            // Arrange
            Mock<ModelMetadataProvider> provider = new Mock<ModelMetadataProvider>();
            ModelMetadata metadata = new ModelMetadata(provider.Object, null, null, typeof(object), "PropertyName") { DisplayName = "Display Name" };

            // Act
            string result = metadata.GetDisplayName();

            // Assert
            Assert.Equal("Display Name", result);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:12,代码来源:ModelMetadataTest.cs


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