• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# ModelMetadata类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ModelMetadata的典型用法代码示例。如果您正苦于以下问题:C# ModelMetadata类的具体用法?C# ModelMetadata怎么用?C# ModelMetadata使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: ApplyMetadataAwareAttributes

 private static void ApplyMetadataAwareAttributes(IEnumerable<Attribute> attributes, ModelMetadata result)
 {
     foreach (IMetadataAware awareAttribute in attributes.OfType<IMetadataAware>())
     {
         awareAttribute.OnMetadataCreated(result);
     }
 }
开发者ID:KevMoore,项目名称:aspnetwebstack,代码行数:7,代码来源:AssociatedMetadataProvider.cs


示例2: GetClientValidationRules

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var name = metadata.GetDisplayName();
            var message = FormatErrorMessage(name);

            yield return new TodayOrLaterClientValidationRule(message);
        }
开发者ID:davidpadbury,项目名称:aspmvc-jquery-win,代码行数:7,代码来源:TodayOrLaterAttribute.cs


示例3: GetClientValidationRules

        /// <summary>
        /// When implemented in a class, returns client validation rules for that class.
        /// </summary>
        /// <param name="metadata">The model metadata.</param>
        /// <param name="context">The controller context.</param>
        /// <returns>
        /// The client validation rules for this validator.
        /// </returns>
        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            var rule = new ModelClientValidationRule { ErrorMessage = ErrorMessageString ?? "Field invalid. Field can only contain alphanumeric characters: 'a-z', 'A-Z', '0-9'.", ValidationType = clientValidationRule };
            rule.ValidationParameters.Add("pattern", RootModuleConstants.AlphanumericExpression);

            yield return rule;
        }
开发者ID:vivekmalikymca,项目名称:BetterCMS,代码行数:15,代码来源:DisallowNonAlphanumericAttribute.cs


示例4: DefaultValues

        public void DefaultValues()
        {
            // Arrange
            Mock<ModelMetadataProvider> provider = new Mock<ModelMetadataProvider>();

            // Act
            ModelMetadata metadata = new ModelMetadata(provider.Object, typeof(Exception), () => "model", typeof(string), "propertyName");

            // Assert
            Assert.Equal(typeof(Exception), metadata.ContainerType);
            Assert.True(metadata.ConvertEmptyStringToNull);
            Assert.Null(metadata.DataTypeName);
            Assert.Null(metadata.Description);
            Assert.Null(metadata.DisplayFormatString);
            Assert.Null(metadata.DisplayName);
            Assert.Null(metadata.EditFormatString);
            Assert.False(metadata.HideSurroundingHtml);
            Assert.Equal("model", metadata.Model);
            Assert.Equal(typeof(string), metadata.ModelType);
            Assert.Null(metadata.NullDisplayText);
            Assert.Equal(10000, metadata.Order);
            Assert.Equal("propertyName", metadata.PropertyName);
            Assert.False(metadata.IsReadOnly);
            Assert.True(metadata.RequestValidationEnabled);
            Assert.Null(metadata.ShortDisplayName);
            Assert.True(metadata.ShowForDisplay);
            Assert.True(metadata.ShowForEdit);
            Assert.Null(metadata.TemplateHint);
            Assert.Null(metadata.Watermark);
        }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:30,代码来源:ModelMetadataTest.cs


示例5: OnMetadataCreated

        public virtual void OnMetadataCreated(ModelMetadata metadata)
        {
            string smallKey = Name.ToLowerInvariant();
            string key = string.Format(CultureInfo.InvariantCulture, Prefix, smallKey);

            metadata.AdditionalValues[key] = Value;
        }
开发者ID:DigitalOkha,项目名称:MVC-3-Html5EditorFor,代码行数:7,代码来源:HtmlAttribute.cs


示例6: OnMetadataProcess

        protected override void OnMetadataProcess(ModelMetadata meta, string name, ViewDataDictionary viewData, ControllerContext context)
        {
            base.OnMetadataProcess(meta, name, viewData, context);

            if (name.IsEmpty())
            {
                throw new Exception("Name from ControlFor is empty");
            }

            this.Name = name;

            if (meta.IsReadOnly)
            {
                this.ReadOnly = true;
            }

            if (this.FieldLabel.IsEmpty())
            {
                this.FieldLabel = meta.GetDisplayName();
            }

            if (this.Note.IsEmpty() && meta.Description.IsNotEmpty())
            {
                this.Note = meta.Description;
            }

            ModelState modelState;
            if (viewData.ModelState.TryGetValue(name, out modelState))
            {
                if (modelState.Errors.Count > 0)
                {
                    this.CustomConfig.Add(new ConfigItem("activeError", JSON.Serialize(modelState.Errors.Select(e => e.ErrorMessage)), ParameterMode.Raw));
                }
            }
        }
开发者ID:emayk,项目名称:Ext.NET.Pro,代码行数:35,代码来源:Field.cs


示例7: ListBox

 public ListBox(HtmlHelper html, string htmlFieldName, IEnumerable<SelectListItem> selectList, ModelMetadata metadata)
 {
     this.html = html;
     this._model.htmlFieldName = htmlFieldName;
     this._model.selectList = selectList;
     this._model.metadata = metadata;
 }
开发者ID:andrewreyes,项目名称:NiftyMvcHelpers,代码行数:7,代码来源:ListBox.cs


示例8: GetClientValidationRules

 public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
 {
     var rule = new ModelClientValidationRule();
     rule.ErrorMessage = FormatErrorMessage(metadata.GetDisplayName());
     rule.ValidationType = "dbisbool";
     yield return rule;
 }
开发者ID:naishan,项目名称:SDDB,代码行数:7,代码来源:DbDataAnnotations.cs


示例9: MultipleAttributesCanSetValuesOnMetadata

        public void MultipleAttributesCanSetValuesOnMetadata()
        {
            // Arrange
            string name1 = "name1";
            string name2 = "name2";

            object value1 = new object();
            object value2 = new object();
            object value3 = new object();

            ModelMetadata modelMetadata = new ModelMetadata(new Mock<ModelMetadataProvider>().Object, null, null, typeof(object), null);
            AdditionalMetadataAttribute attr1 = new AdditionalMetadataAttribute(name1, value1);
            AdditionalMetadataAttribute attr2 = new AdditionalMetadataAttribute(name2, value2);
            AdditionalMetadataAttribute attr3 = new AdditionalMetadataAttribute(name1, value3);

            // Act
            attr1.OnMetadataCreated(modelMetadata);
            attr2.OnMetadataCreated(modelMetadata);
            attr3.OnMetadataCreated(modelMetadata);

            // Assert
            Assert.Equal(2, modelMetadata.AdditionalValues.Count);
            Assert.Equal(modelMetadata.AdditionalValues[name1], value3);
            Assert.Equal(modelMetadata.AdditionalValues[name2], value2);

            Assert.NotEqual(attr1.TypeId, attr2.TypeId);
            Assert.NotEqual(attr2.TypeId, attr3.TypeId);
            Assert.NotEqual(attr3.TypeId, attr1.TypeId);
        }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:29,代码来源:AdditionalMetadataAttributeTest.cs


示例10: GetValidators

 //private class LocalizableAttributeCacheKey
 //{
 //    public LocalizableAttributeCacheKey(Attribute attribute)
 //    {
 //        string cacheFormat = "Attribute HashCode:{0}; CultureName LCID:{1}";
 //        this.CacheKey = string.Format(cacheFormat, attribute.GetHashCode(), System.Threading.Thread.CurrentThread.CurrentCulture.LCID);
 //    }
 //    public string CacheKey { get; private set; }
 //    public override int GetHashCode()
 //    {
 //        return CacheKey.GetHashCode();
 //    }
 //    public override bool Equals(object obj)
 //    {
 //        return this.GetHashCode() == ((LocalizableAttributeCacheKey)obj).GetHashCode();
 //    }
 //}
 //private static readonly List<LocalizableAttributeCacheKey> localized = new List<LocalizableAttributeCacheKey>();
 //protected override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context, IEnumerable<Attribute> attributes)
 //{
 //    foreach (ValidationAttribute attribute in attributes.OfType<ValidationAttribute>())
 //    {
 //        var cacheKey = new LocalizableAttributeCacheKey(attribute);
 //        if (!localized.Contains(cacheKey))
 //        {
 //            lock (localized)
 //            {
 //                if (!localized.Contains(cacheKey))
 //                {
 //                    if (!string.IsNullOrWhiteSpace(attribute.ErrorMessage))
 //                    {
 //                        attribute.ErrorMessage = attribute.ErrorMessage.Localize();
 //                    }
 //                    else
 //                    {
 //                        if (attribute is RequiredAttribute)
 //                        {
 //                            attribute.ErrorMessage = "Required".Localize();
 //                        }
 //                    }
 //                    localized.Add(cacheKey);
 //                }
 //            }
 //        }
 //    }
 //    var validators = base.GetValidators(metadata, context, attributes);
 //    return validators;
 //}
 protected override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context, IEnumerable<Attribute> attributes)
 {
     foreach (var validator in base.GetValidators(metadata, context, attributes))
     {
         yield return new ModelValidatorWrapper(validator, metadata, context);
     }
 }
开发者ID:Godoy,项目名称:CMS,代码行数:55,代码来源:KoobooDataAnnotationsModelValidatorProvider.cs


示例11: OnMetadataCreated

 /// <summary>
 /// When implemented in a class, provides metadata to the model metadata creation process.
 /// </summary>
 /// <param name="metadata">The model metadata.</param>
 public void OnMetadataCreated(ModelMetadata metadata)
 {
     metadata.AdditionalValues.Add("LookupMethodName", this.LookupMethodName);
     metadata.AdditionalValues.Add("AddLookupData", this.AddLookupData);
     metadata.AdditionalValues.Add("LookupType",this.LookupType);
     metadata.TemplateHint = "DropDownList";
 }
开发者ID:rawiisshekhar,项目名称:MyProject,代码行数:11,代码来源:DropDownAttribute.cs


示例12: GetClientValidationRules

 /// <summary>
 /// Gets the client validation rules.
 /// </summary>
 /// <param name="metadata">The metadata.</param>
 /// <param name="context">The context.</param>
 /// <returns>The client validation rules</returns>
 public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
 {
     return new[]
         {
             new ModelClientValidationStringLengthRule(this.FormatErrorMessage(metadata.GetDisplayName()), this.minimumCharacterCount, int.MaxValue)
         };
 }
开发者ID:mrjavaguy,项目名称:Ninject.Web.Mvc,代码行数:13,代码来源:ValidatePasswordLengthAttribute.cs


示例13: GetValidators

        public override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, ControllerContext context)
        {
            var validators = new List<ModelValidator>();

            if (metadata is FluentModelMetadata)
            {
                var isPropertyMetadata = !string.IsNullOrEmpty(metadata.PropertyName);
                var rules = (metadata as FluentModelMetadata).Metadata.Rules;
                if (isPropertyMetadata)
                {
                    validators.AddRange(
                        rules
                            .Select(rule => new RuleModelValidator(rule, metadata, context))
                            .Cast<ModelValidator>()); //TODO unnecessary for .NET 4
                }
                else
                {
                    validators.AddRange(
                        rules
                            .Select(rule => new ClassRuleModelValidator(rule as IClassRule, metadata, context))
                            .Cast<ModelValidator>()); //TODO unnecessary for .NET 4
                }
            }

            return validators;
        }
开发者ID:forger,项目名称:FluentMetadata,代码行数:26,代码来源:FluentValidationProvider.cs


示例14: MyValidator

			public MyValidator(ValidationAttribute attribute, string errorMsg, ModelMetadata metadata, ControllerContext controllerContext, IEnumerable<ModelClientValidationRule> create)
				: base(metadata, controllerContext)
			{
				_attribute = attribute;
				_errorMsg = errorMsg;
				_create = create;
			}
开发者ID:damirarh,项目名称:griffin.mvccontrib,代码行数:7,代码来源:LocalizedModelValidatorProvider.cs


示例15: TransformMetadata

 public void TransformMetadata(ModelMetadata metadata, IEnumerable<Attribute> attributes)
 {
     if (!string.IsNullOrEmpty(metadata.PropertyName) && !attributes.OfType<DisplayNameAttribute>().Any())
     {
         metadata.DisplayName = metadata.PropertyName.ToProperCaseWords();
     }
 }
开发者ID:Gwayaboy,项目名称:iDeal,代码行数:7,代码来源:PascalCaseToDisplayNameFilter.cs


示例16: BootstrapRadioButton

 public BootstrapRadioButton(HtmlHelper html, string htmlFieldName, object value, ModelMetadata metadata)
 {
     this.html = html;
     this._model.htmlFieldName = htmlFieldName;
     this._model.value = value;
     this._model.metadata = metadata;
 }
开发者ID:joypipi,项目名称:TwitterBootstrapMvc,代码行数:7,代码来源:BootstrapRadioButton.cs


示例17: GetClientValidationRules

        public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
        {
            if (!Required)
                yield break;

            yield return new ReferenceRequiredValidationRule(ErrorMessage, Required);
        }
开发者ID:carlospeix,项目名称:ConfUi,代码行数:7,代码来源:ReferenceAttribute.cs


示例18: OnMetadataCreated

 public void OnMetadataCreated(ModelMetadata metadata)
 {
     metadata.AdditionalValues.Add("dropdownlistenerwithspecificvalue", true);
     metadata.AdditionalValues.Add("dropdownlistenerwithspecificvalue-match", _matchingValue);
     metadata.AdditionalValues.Add("dropdownlistenerwithspecificvalue-callback", _clientCallback);
     metadata.AdditionalValues.Add("dropdownlistenerwithspecificvalue-parent", _parent);
 }
开发者ID:rodmjay,项目名称:ScaffR-Generated,代码行数:7,代码来源:DropDownListenerWithSpecificValueAttribute.cs


示例19: GetClientValidationRules

 public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
 {
     yield return new ModelClientValidationRule {
         ErrorMessage = this.ErrorMessage,
         ValidationType = "mustbetrue"
     };
 }
开发者ID:plurby,项目名称:MvcDoodle,代码行数:7,代码来源:MustBeTrueAttribute.cs


示例20: OnMetadataCreated

 public void OnMetadataCreated(ModelMetadata metadata)
 {
     metadata.AdditionalValues[UxAttributeKeys.Boolean.TrueText] = TrueText;
     metadata.AdditionalValues[UxAttributeKeys.Boolean.FalseText] = FalseText;
     metadata.AdditionalValues[UxAttributeKeys.Boolean.NullText] = NullText;
     metadata.AdditionalValues[UxAttributeKeys.Boolean.Type] = Type;
 }
开发者ID:renhammington,项目名称:UxFoundation,代码行数:7,代码来源:UxBooleanAttribute.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# ModelNode类代码示例发布时间:2022-05-24
下一篇:
C# ModelMapper类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap