本文整理汇总了C#中System.Reflection.PropertyInfo.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# PropertyInfo.ThrowIfNull方法的具体用法?C# PropertyInfo.ThrowIfNull怎么用?C# PropertyInfo.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.PropertyInfo
的用法示例。
在下文中一共展示了PropertyInfo.ThrowIfNull方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapAsync
public Task<MapResult> MapAsync(HttpRequestBase request, Type modelType, PropertyInfo property)
{
request.ThrowIfNull("request");
modelType.ThrowIfNull("modelType");
property.ThrowIfNull("property");
return MapResult.ValueMapped(property.PropertyType.GetDefaultValue()).AsCompletedTask();
}
示例2: Map
public MapResult Map(HttpRequestBase request, Type modelType, PropertyInfo property)
{
request.ThrowIfNull("request");
modelType.ThrowIfNull("modelType");
property.ThrowIfNull("property");
return MapResult.ValueMapped(property.PropertyType.GetDefaultValue());
}
示例3: MapAsync
public Task<MapResult> MapAsync(HttpContextBase context, Type modelType, PropertyInfo property)
{
context.ThrowIfNull("context");
modelType.ThrowIfNull("modelType");
property.ThrowIfNull("property");
Type propertyType = property.PropertyType;
string propertyName = property.Name;
NameValueCollection nameValueCollection;
switch (_source)
{
case NameValueCollectionSource.Form:
nameValueCollection = context.Request.Form;
break;
case NameValueCollectionSource.QueryString:
nameValueCollection = context.Request.QueryString;
break;
default:
throw new InvalidOperationException(String.Format("Unexpected name-value collection source {0}.", _source));
}
string field = nameValueCollection.AllKeys.LastOrDefault(arg => String.Equals(arg, propertyName, _caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase));
if (field == null)
{
return MapResult.ValueNotMapped().AsCompletedTask();
}
string value = nameValueCollection[field];
try
{
return OnMapAsync(context, value, propertyType);
}
catch (Exception exception)
{
if (_errorHandling == DataConversionErrorHandling.ThrowException)
{
throw new ApplicationException(
String.Format(
"Value of form field '{0}' could not be converted to property '{1} {2}' of type '{3}'.",
field,
propertyType.FullName,
propertyName,
modelType.FullName),
exception);
}
return MapResult.ValueMapped(propertyType.GetDefaultValue()).AsCompletedTask();
}
}
示例4: MapAsync
public Task<MapResult> MapAsync(HttpRequestBase request, Type modelType, PropertyInfo property)
{
request.ThrowIfNull("request");
modelType.ThrowIfNull("modelType");
property.ThrowIfNull("property");
Type propertyType = property.PropertyType;
string propertyName = property.Name;
string field = request.QueryString.AllKeys.LastOrDefault(arg => String.Equals(arg, propertyName, _caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase));
if (field == null)
{
return MapResult.ValueNotMapped().AsCompletedTask();
}
IConvertible value = request.QueryString[field];
object convertedValue;
try
{
convertedValue = value.ToType(propertyType, CultureInfo.InvariantCulture);
}
catch (Exception exception)
{
if (_errorHandling == DataConversionErrorHandling.ThrowException)
{
throw new ApplicationException(
String.Format(
"Value of query string field '{0}' could not be converted to property '{1} {2}' of type '{3}'.",
field,
propertyType.FullName,
propertyName,
modelType.FullName),
exception);
}
convertedValue = propertyType.GetDefaultValue();
}
return MapResult.ValueMapped(convertedValue).AsCompletedTask();
}