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


C# ModelMetadata类代码示例

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


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


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