本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}