本文整理汇总了C#中System.Reflection.MethodInfo.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# MethodInfo.ThrowIfNull方法的具体用法?C# MethodInfo.ThrowIfNull怎么用?C# MethodInfo.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.MethodInfo
的用法示例。
在下文中一共展示了MethodInfo.ThrowIfNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Map
public IdResult Map(Type type, MethodInfo method)
{
type.ThrowIfNull("type");
method.ThrowIfNull("method");
return IdResult.IdMapped(_guidFactory.Random());
}
示例3: 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();
}
示例4: MustAuthenticateAsync
public Task<bool> MustAuthenticateAsync(Type type, MethodInfo method)
{
type.ThrowIfNull("type");
method.ThrowIfNull("method");
return method.GetCustomAttributes(typeof(AuthenticateAttribute), false).Any().AsCompletedTask();
}
示例5: MustAuthenticate
public bool MustAuthenticate(Type type, MethodInfo method)
{
type.ThrowIfNull("type");
method.ThrowIfNull("method");
return method.GetCustomAttributes(typeof(AuthenticateAttribute), false).Any();
}
示例6: GetParameterValuesAsync
public async Task<IEnumerable<object>> GetParameterValuesAsync(HttpContextBase context, Type type, MethodInfo method)
{
context.ThrowIfNull("context");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
ParameterInfo[] parameterInfos = method.GetParameters();
var parameterValues = new List<object>();
foreach (ParameterInfo parameterInfo in parameterInfos)
{
Type parameterType = parameterInfo.ParameterType;
string parameterName = parameterInfo.Name;
Type currentParameterType = parameterType;
do
{
bool mapped = false;
foreach (IParameterMapper parameterMapper in _parameterMappers)
{
if (!await parameterMapper.CanMapTypeAsync(context, parameterType))
{
continue;
}
MapResult mapResult = await parameterMapper.MapAsync(context, type, method, parameterInfo);
if (mapResult.ResultType == MapResultType.ValueNotMapped)
{
continue;
}
parameterValues.Add(mapResult.Value);
mapped = true;
break;
}
if (mapped)
{
break;
}
currentParameterType = currentParameterType.BaseType;
} while (currentParameterType != null);
if (currentParameterType == null)
{
throw new ApplicationException(
String.Format(
"No request parameter mapper was found for parameter '{0} {1}' of {2}.{3}.",
parameterType.FullName,
parameterName,
type.FullName,
method.Name));
}
}
return parameterValues;
}
示例7: Map
public void Map(Func<IContainer> container, Type type, MethodInfo method, Routing.Route route)
{
container.ThrowIfNull("container");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
route.ThrowIfNull("route");
route.RespondWithNoContent();
}
示例8: 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();
}
示例9: MapAsync
public Task<NameResult> MapAsync(Type type, MethodInfo method)
{
type.ThrowIfNull("type");
method.ThrowIfNull("method");
NameAttribute attribute = method.GetCustomAttributes(typeof(NameAttribute), false).Cast<NameAttribute>().SingleOrDefault();
return (attribute != null ? NameResult.NameMapped(attribute.Name) : NameResult.NameNotMapped()).AsCompletedTask();
}
示例10: MapAsync
public Task<IdResult> MapAsync(Type type, MethodInfo method)
{
type.ThrowIfNull("type");
method.ThrowIfNull("method");
IdAttribute attribute = method.GetCustomAttributes(typeof(IdAttribute), false).Cast<IdAttribute>().SingleOrDefault();
return (attribute != null ? IdResult.IdMapped(attribute.Id) : IdResult.IdNotMapped()).AsCompletedTask();
}
示例11: 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());
}
示例12: GetControllerMethod
public virtual MethodInfo GetControllerMethod(string methodName)
{
methodName = _namingConvention.GetMethodInfoByMethodNameFromInstance(_BusinessInstance, methodName);
if (_requestedMethod == null)
{
_requestedMethod = _BusinessInstance.GetType().GetMethod(methodName);
_requestedMethod.ThrowIfNull("methodInfo");
}
return _requestedMethod;
}
示例13: Map
public ResolvedRelativeUrlResult Map(Type type, MethodInfo method)
{
type.ThrowIfNull("type");
method.ThrowIfNull("method");
ResolvedRelativeUrlAttribute attribute = method.GetCustomAttributes(typeof(ResolvedRelativeUrlAttribute), false).Cast<ResolvedRelativeUrlAttribute>().SingleOrDefault();
return attribute != null
? ResolvedRelativeUrlResult.ResolvedRelativeUrlMapped(attribute.ResolvedRelativeUrl)
: ResolvedRelativeUrlResult.ResolvedRelativeUrlNotMapped();
}
示例14: MapAsync
public Task MapAsync(Func<IContainer> container, Type type, MethodInfo method, Routing.Route route)
{
container.ThrowIfNull("container");
type.ThrowIfNull("type");
method.ThrowIfNull("method");
route.ThrowIfNull("route");
route.RespondWithNoContent();
return Task.Factory.Empty();
}
示例15: Map
public void Map(Type type, MethodInfo method, Routing.Route route, IContainer container)
{
type.ThrowIfNull("type");
method.ThrowIfNull("method");
route.ThrowIfNull("route");
container.ThrowIfNull("container");
IEnumerable<RelativeUrlResolverAttribute> attributes = method.GetCustomAttributes<RelativeUrlResolverAttribute>(false);
foreach (RelativeUrlResolverAttribute attribute in attributes)
{
attribute.Map(route, container);
}
}