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


C# IValueProvider.ContainsPrefix方法代码示例

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


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

示例1: GetModel

        public object GetModel(ControllerContext controllerContext, Type modelType, IValueProvider valueProvider, string key)
        {
            if (!valueProvider.ContainsPrefix(key))
            {
                return null;
            }
            ModelMetadata modelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, modelType);
            if (!modelMetadata.IsComplexType)
            {
                return valueProvider.GetValue(key).ConvertTo(modelType);
            }

            if (modelType.IsArray)
            {
                return GetArrayModel(controllerContext, modelType, valueProvider,key);
            }

            Type enumerableType = ExtractGenericInterface(modelType, typeof(IEnumerable<>));
            if (null != enumerableType)
            {
                return GetCollectionModel(controllerContext, modelType, valueProvider, key);
            }         
           
            if (modelMetadata.IsComplexType)
            {
                return GetComplexModel(controllerContext, modelType, valueProvider, key);
            }
            return null;
        }
开发者ID:xiaohong2015,项目名称:.NET,代码行数:29,代码来源:DefaultModelBinder.cs

示例2: GetDictionaryModel

        protected virtual object GetDictionaryModel(ControllerContext controllerContext, Type modelType, IValueProvider valueProvider, string prefix)
        {
            List<KeyValuePair<object, object>> list = new List<KeyValuePair<object, object>>();

            bool numericIndex;
            IEnumerable<string> indexes = GetIndexes(prefix, valueProvider, out numericIndex);
            Type[] genericArguments = modelType.GetGenericArguments();
            Type keyType = genericArguments[0];
            Type valueType = genericArguments[1];

            foreach (var index in indexes)
            {
                string indexPrefix = prefix + "[" + index + "]";
                if (!valueProvider.ContainsPrefix(indexPrefix) && numericIndex)
                {
                    break;
                }
                string keyPrefix = indexPrefix + ".Key";
                string valulePrefix = indexPrefix + ".Value";
                object key = GetModel(controllerContext, keyType,
                                           valueProvider, keyPrefix);
                object value = GetModel(controllerContext, valueType,
                                           valueProvider, valulePrefix);
                list.Add(new KeyValuePair<object, object>(key, value));
            }
            object model = CreateModel(modelType);
            ReplaceHelper.ReplaceDictionary(keyType, valueType, model, list);
            return model;
        }
开发者ID:xiaohong2015,项目名称:.NET,代码行数:29,代码来源:DefaultModelBinder.cs

示例3: GetModel

 public object GetModel(ControllerContext controllerContext, Type modelType, IValueProvider valueProvider, string key)
 {
     if (!valueProvider.ContainsPrefix(key))
     {
         return null;
     }
     return valueProvider.GetValue(key).ConvertTo(modelType);
 }
开发者ID:xiaohong2015,项目名称:.NET,代码行数:8,代码来源:DefaultModelBinder.cs

示例4: ApplyValues

        /// <summary>
        /// 在表单上应用指定值提供程序的值
        /// </summary>
        /// <param name="form">要应用的表单</param>
        /// <param name="valueProvider">提供值的 ValueProvider 实例</param>
        /// <returns>返回表单,便于链式调用</returns>
        public static HtmlForm ApplyValues( this HtmlForm form, IValueProvider valueProvider )
        {
            foreach ( var key in form.InputControls.Select( c => c.Name ) )
              {
            if ( valueProvider.ContainsPrefix( key ) )
            {
              form[key].TrySetValue( valueProvider.GetValue( key ).AttemptedValue );
            }
              }

              return form;
        }
开发者ID:neo2018,项目名称:Jumony,代码行数:18,代码来源:MvcFormExtensions.cs

示例5: GetArrayModel

 protected virtual object GetArrayModel( ControllerContext controllerContext, Type modelType, IValueProvider valueProvider, string prefix)
 {
     if (valueProvider.ContainsPrefix(prefix) && !string.IsNullOrEmpty(prefix))
     {
         ValueProviderResult result = valueProvider.GetValue(prefix);
         if (null != result)
         {
             return result.ConvertTo(modelType);
         }
     }
     return null;
 }  
开发者ID:xiaohong2015,项目名称:.NET,代码行数:12,代码来源:DefaultModelBinder.cs

示例6: ApplyValues

    /// <summary>
    /// 在表单上应用指定值提供程序的值
    /// </summary>
    /// <param name="form">要应用的表单</param>
    /// <param name="valueProvider">提供值的 ValueProvider 实例</param>
    /// <returns>返回表单,便于链式调用</returns>
    public static HtmlForm ApplyValues( this HtmlForm form, IValueProvider valueProvider )
    {

      foreach ( var control in form.Controls )
      {
        if ( valueProvider.ContainsPrefix( control.Name ) )
          control.Value = valueProvider.GetValue( control.Name ).AttemptedValue;
      }

      return form;

    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:18,代码来源:MvcFormExtensions.cs

示例7: GetModel

 public object GetModel(ControllerContext controllerContext, Type modelType, IValueProvider valueProvider, string key)
 {
     if (!valueProvider.ContainsPrefix(key))
     {
         return null;
     }
     ModelMetadata modelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, modelType);
     if (!modelMetadata.IsComplexType)
     {
         return valueProvider.GetValue(key).ConvertTo(modelType);
     }
     if (modelMetadata.IsComplexType)
     {
         return GetComplexModel(controllerContext, modelType, valueProvider, key);
     }
     return null;
 }
开发者ID:xiaohong2015,项目名称:.NET,代码行数:17,代码来源:DefaultModelBinder.cs

示例8: GetListModel

 private List<object> GetListModel(ControllerContext controllerContext, Type modelType, Type elementType, IValueProvider valueProvider, string prefix)
 {
     List<object> list = new List<object>();
     if (!string.IsNullOrEmpty(prefix) && valueProvider.ContainsPrefix(prefix))
     {
         ValueProviderResult result = valueProvider.GetValue(prefix);
         if (null != result)
         {
             IEnumerable enumerable = result.ConvertTo(modelType) as IEnumerable;
             foreach (var value in enumerable)
             {
                 list.Add(value);
             }
         }
     }
     bool numericIndex;
     IEnumerable<string> indexes = GetIndexes(prefix, valueProvider, out numericIndex);
     foreach (var index in indexes)
     {
         string indexPrefix = prefix + "[" + index + "]";
         if (!valueProvider.ContainsPrefix(indexPrefix) && numericIndex)
         {
             break;
         }
         list.Add(GetModel(controllerContext, elementType, valueProvider, indexPrefix));
     }
     return list;
 }
开发者ID:xiaohong2015,项目名称:.NET,代码行数:28,代码来源:DefaultModelBinder.cs

示例9: GetPropertyValueForFile

        private static PropertyValue GetPropertyValueForFile(
            Property property,
            IValueProvider valueProvider,
            HttpFileCollectionBase files)
        {
            var propertyValue = new PropertyValue(property);

            var file = files[property.Name];
            propertyValue.Raw = file;
            if (property.TypeInfo.IsFileStoredInDb == false &&
                property.FileOptions.NameCreation == NameCreation.UserInput)
            {
                var providedName = (string)valueProvider.GetValue(property.Name)
                    .ConvertTo(typeof(string), CultureInfo.CurrentCulture);
                propertyValue.Additional = providedName;
            }
            var isDeleted = false;

            if (file == null || file.ContentLength > 0)
            {
                isDeleted = false;
            }
            else
            {
                var isDeletedKey = property.Name + "_delete";
                if (valueProvider.ContainsPrefix(isDeletedKey))
                {
                    isDeleted =
                       ((bool?)
                           valueProvider.GetValue(isDeletedKey)
                               .ConvertTo(typeof(bool), CultureInfo.CurrentCulture)).GetValueOrDefault();
                }
            }

            if (isDeleted)
            {
                propertyValue.DataBehavior = DataBehavior.Clear;
                propertyValue.Additional = null;
            }

            return propertyValue;
        }
开发者ID:rgonek,项目名称:Ilaro.Admin,代码行数:42,代码来源:EntityRecordCreator.cs


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