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


C# DataAnnotationsModelMetadataProvider.GetMetadataForType方法代码示例

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


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

示例1: GetMetadataForTypeSetsTypeWithNullPropertyName

        public void GetMetadataForTypeSetsTypeWithNullPropertyName() {
            // Arrange
            DataAnnotationsModelMetadataProvider provider = new DataAnnotationsModelMetadataProvider();

            // Act
            ModelMetadata result = provider.GetMetadataForType(null, typeof(string));

            // Assert
            Assert.AreEqual(typeof(string), result.ModelType);
            Assert.IsNull(result.PropertyName);
        }
开发者ID:consumentor,项目名称:Server,代码行数:11,代码来源:DataAnnotationsModelMetadataProviderTest.cs

示例2: GetMetadataForType

 private static ModelMetadata GetMetadataForType(Type t)
 {
     DataAnnotationsModelMetadataProvider metadataProvider = new DataAnnotationsModelMetadataProvider();
     return metadataProvider.GetMetadataForType(null, t);
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:5,代码来源:MutableObjectModelBinderTest.cs

示例3: GetMetadataForObject

 private static ModelMetadata GetMetadataForObject(object o)
 {
     DataAnnotationsModelMetadataProvider metadataProvider = new DataAnnotationsModelMetadataProvider();
     return metadataProvider.GetMetadataForType(() => o, o.GetType());
 }
开发者ID:huangw-t,项目名称:aspnetwebstack,代码行数:5,代码来源:MutableObjectModelBinderTest.cs

示例4: SimpleDisplayTextForNonNullClassWithNullDisplayColumnValueRevertsToDefaultBehavior

        public void SimpleDisplayTextForNonNullClassWithNullDisplayColumnValueRevertsToDefaultBehavior() {
            // Arrange
            DataAnnotationsModelMetadataProvider provider = new DataAnnotationsModelMetadataProvider();
            SimpleDisplayTextAttributeModel model = new SimpleDisplayTextAttributeModel();
            ModelMetadata metadata = provider.GetMetadataForType(() => model, typeof(SimpleDisplayTextAttributeModel));

            // Act
            string result = metadata.SimpleDisplayText;

            // Assert
            Assert.AreEqual("42", result);    // Falls back to the default logic of first property value
        }
开发者ID:consumentor,项目名称:Server,代码行数:12,代码来源:DataAnnotationsModelMetadataProviderTest.cs

示例5: SimpleDisplayTextForNullClassRevertsToDefaultBehavior

        public void SimpleDisplayTextForNullClassRevertsToDefaultBehavior() {
            // Arrange
            string expected = "Null Display Text";
            DataAnnotationsModelMetadataProvider provider = new DataAnnotationsModelMetadataProvider();
            ModelMetadata metadata = provider.GetMetadataForType(null, typeof(SimpleDisplayTextAttributeModel));
            metadata.NullDisplayText = expected;

            // Act
            string result = metadata.SimpleDisplayText;

            // Assert
            Assert.AreEqual(expected, result);
        }
开发者ID:consumentor,项目名称:Server,代码行数:13,代码来源:DataAnnotationsModelMetadataProviderTest.cs

示例6: SimpleDisplayTextForNonNullClassWithNonNullDisplayColumnValue

        public void SimpleDisplayTextForNonNullClassWithNonNullDisplayColumnValue() {
            // Arrange
            string expected = "Custom property display value";
            DataAnnotationsModelMetadataProvider provider = new DataAnnotationsModelMetadataProvider();
            SimpleDisplayTextAttributeModel model = new SimpleDisplayTextAttributeModel { DisplayColumnProperty = expected };
            ModelMetadata metadata = provider.GetMetadataForType(() => model, typeof(SimpleDisplayTextAttributeModel));

            // Act
            string result = metadata.SimpleDisplayText;

            // Assert
            Assert.AreEqual(expected, result);
        }
开发者ID:consumentor,项目名称:Server,代码行数:13,代码来源:DataAnnotationsModelMetadataProviderTest.cs

示例7: SimpleDisplayTextForTypeWithWriteOnlyDisplayColumnThrows

        public void SimpleDisplayTextForTypeWithWriteOnlyDisplayColumnThrows() {
            // Arrange
            DataAnnotationsModelMetadataProvider provider = new DataAnnotationsModelMetadataProvider();

            // Act & Assert
            ExceptionHelper.ExpectInvalidOperationException(
                () => provider.GetMetadataForType(() => new WriteOnlyDisplayColumnModel(), typeof(WriteOnlyDisplayColumnModel)).SimpleDisplayText,
                "System.Web.Mvc.Test.DataAnnotationsModelMetadataProviderTest+WriteOnlyDisplayColumnModel has a DisplayColumn attribute for WriteOnlyProperty, but property WriteOnlyProperty does not have a public getter.");

            ExceptionHelper.ExpectInvalidOperationException(
                () => provider.GetMetadataForType(() => new PrivateReadPublicWriteDisplayColumnModel(), typeof(PrivateReadPublicWriteDisplayColumnModel)).SimpleDisplayText,
                "System.Web.Mvc.Test.DataAnnotationsModelMetadataProviderTest+PrivateReadPublicWriteDisplayColumnModel has a DisplayColumn attribute for PrivateReadPublicWriteProperty, but property PrivateReadPublicWriteProperty does not have a public getter.");
        }
开发者ID:consumentor,项目名称:Server,代码行数:13,代码来源:DataAnnotationsModelMetadataProviderTest.cs

示例8: SimpleDisplayNameWithUnknownDisplayColumnThrows

        public void SimpleDisplayNameWithUnknownDisplayColumnThrows() {
            // Arrange
            DataAnnotationsModelMetadataProvider provider = new DataAnnotationsModelMetadataProvider();

            // Act & Assert
            ExceptionHelper.ExpectInvalidOperationException(
                () => provider.GetMetadataForType(() => new UnknownDisplayColumnModel(), typeof(UnknownDisplayColumnModel)).SimpleDisplayText,
                "System.Web.Mvc.Test.DataAnnotationsModelMetadataProviderTest+UnknownDisplayColumnModel has a DisplayColumn attribute for NoPropertyWithThisName, but property NoPropertyWithThisName does not exist.");
        }
开发者ID:consumentor,项目名称:Server,代码行数:9,代码来源:DataAnnotationsModelMetadataProviderTest.cs

示例9: CreateBindingContext

 private static ModelBindingContext CreateBindingContext(IModelBinder binder,
                                                         IValueProvider valueProvider,
                                                         Type type,
                                                         IEnumerable<IModelValidatorProvider> validatorProviders = null)
 {
     validatorProviders = validatorProviders ?? Enumerable.Empty<IModelValidatorProvider>();
     var metadataProvider = new DataAnnotationsModelMetadataProvider();
     var bindingContext = new ModelBindingContext
     {
         ModelBinder = binder,
         FallbackToEmptyPrefix = true,
         MetadataProvider = metadataProvider,
         ModelMetadata = metadataProvider.GetMetadataForType(null, type),
         ModelState = new ModelStateDictionary(),
         ValueProvider = valueProvider,
         ValidatorProviders = validatorProviders
     };
     return bindingContext;
 }
开发者ID:Nakro,项目名称:Mvc,代码行数:19,代码来源:CompositeModelBinderTest.cs


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