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