本文整理汇总了C#中System.Reflection.ParameterInfo.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterInfo.ThrowIfNull方法的具体用法?C# ParameterInfo.ThrowIfNull怎么用?C# ParameterInfo.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.ParameterInfo
的用法示例。
在下文中一共展示了ParameterInfo.ThrowIfNull方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MapAsync
public async Task<MapResult> MapAsync(HttpContextBase context, Type type, MethodInfo method, ParameterInfo parameter)
{
context.ThrowIfNull("context");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
parameter.ThrowIfNull("parameter");
Type parameterType = parameter.ParameterType;
object model = _container != null ? _container.GetInstance(parameterType) : Activator.CreateInstance(parameterType);
Type modelType = model.GetType();
foreach (PropertyInfo property in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
object mappedValue = await GetMappedValueAsync(context, modelType, property);
if (mappedValue == null)
{
throw new ApplicationException(String.Format("Unable to map property '{0} {1}' of type '{2}'.", property.PropertyType.FullName, property.Name, modelType.FullName));
}
property.SetValue(model, mappedValue, null);
}
return MapResult.ValueMapped(model);
}
示例2: MapAsync
public Task<MapResult> MapAsync(HttpContextBase context, Type type, MethodInfo method, ParameterInfo parameter)
{
context.ThrowIfNull("request");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
parameter.ThrowIfNull("parameter");
Type parameterType = parameter.ParameterType;
var reader = new StreamReader(context.Request.InputStream, context.Request.ContentEncoding);
string json = reader.ReadToEnd();
object jsonModel;
try
{
jsonModel = JsonConvert.DeserializeObject(json, parameterType, _serializerSettings);
}
catch (Exception exception)
{
if (_errorHandling == DataConversionErrorHandling.ThrowException)
{
throw new ApplicationException(String.Format("Request content could not be deserialized to '{0}'.", parameterType.FullName), exception);
}
jsonModel = parameterType.GetDefaultValue();
}
return MapResult.ValueMapped(jsonModel).AsCompletedTask();
}
示例3: Map
public MapResult Map(HttpRequestBase request, Type type, MethodInfo method, ParameterInfo parameter)
{
request.ThrowIfNull("request");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
parameter.ThrowIfNull("parameter");
return MapResult.ValueMapped(parameter.ParameterType.GetDefaultValue());
}
示例4: MapAsync
public Task<MapResult> MapAsync(HttpContextBase context, Type type, MethodInfo method, ParameterInfo parameter)
{
context.ThrowIfNull("context");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
parameter.ThrowIfNull("parameter");
return MapResult.ValueMapped(context.Server).AsCompletedTask();
}
示例5: MapAsync
public Task<MapResult> MapAsync(HttpContextBase context, Type type, MethodInfo method, ParameterInfo parameter)
{
context.ThrowIfNull("context");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
parameter.ThrowIfNull("parameter");
Type parameterType = parameter.ParameterType;
string parameterName = parameter.Name;
string field = context.Request.Form.AllKeys.LastOrDefault(arg => String.Equals(arg, parameterName, _caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase));
if (field == null)
{
return MapResult.ValueNotMapped().AsCompletedTask();
}
IConvertible value = context.Request.Form[field];
object convertedValue;
try
{
convertedValue = value.ToType(parameterType, CultureInfo.InvariantCulture);
}
catch (Exception exception)
{
if (_errorHandling == DataConversionErrorHandling.ThrowException)
{
throw new ApplicationException(
String.Format(
"Value for form field '{0}' could not be converted to parameter '{1} {2}' of {3}.{4}.",
field,
parameterType.FullName,
parameterName,
type.FullName,
method.Name),
exception);
}
convertedValue = parameterType.GetDefaultValue();
}
return MapResult.ValueMapped(convertedValue).AsCompletedTask();
}
示例6: Map
public MapResult Map(HttpRequestBase request, Type type, MethodInfo method, ParameterInfo parameter)
{
request.ThrowIfNull("request");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
parameter.ThrowIfNull("parameter");
Type parameterType = parameter.ParameterType;
object model = _container != null ? _container.GetInstance(parameterType) : Activator.CreateInstance(parameterType);
Type modelType = model.GetType();
foreach (PropertyInfo property in modelType.GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
PropertyInfo closureProperty = property;
var mappedValue = _modelPropertyMappers
.Select(arg => new { Mapper = arg, MapResult = arg.Map(request, modelType, closureProperty) })
.FirstOrDefault(arg => arg.MapResult.ResultType == MapResultType.ValueMapped);
if (mappedValue == null)
{
throw new ApplicationException(String.Format("Unable to map property '{0} {1}' of type '{2}'.", property.PropertyType.FullName, property.Name, modelType.FullName));
}
property.SetValue(model, mappedValue.MapResult.Value, null);
}
return MapResult.ValueMapped(model);
}