本文整理汇总了C#中System.Type.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# Type.ThrowIfNull方法的具体用法?C# Type.ThrowIfNull怎么用?C# Type.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.ThrowIfNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: CanMapTypeAsync
public Task<bool> CanMapTypeAsync(HttpContextBase context, Type parameterType)
{
context.ThrowIfNull("context");
parameterType.ThrowIfNull("parameterType");
return (parameterType == typeof(HttpServerUtilityBase)).AsCompletedTask();
}
示例3: CanMapType
public bool CanMapType(HttpRequestBase request, Type parameterType)
{
request.ThrowIfNull("request");
parameterType.ThrowIfNull("parameterType");
return true;
}
示例4: CanMapTypeAsync
public async Task<bool> CanMapTypeAsync(HttpContextBase context, Type parameterType)
{
context.ThrowIfNull("context");
parameterType.ThrowIfNull("parameterType");
return context.Request.ContentType == "application/json" && await Task.Run(() => _parameterTypeMatchDelegate(parameterType));
}
示例5: Map
public IdResult Map(Type type, MethodInfo method)
{
type.ThrowIfNull("type");
method.ThrowIfNull("method");
return IdResult.IdMapped(_guidFactory.Random());
}
示例6: MustAuthenticateAsync
public Task<bool> MustAuthenticateAsync(Type type, MethodInfo method)
{
type.ThrowIfNull("type");
method.ThrowIfNull("method");
return method.GetCustomAttributes(typeof(AuthenticateAttribute), false).Any().AsCompletedTask();
}
示例7: MustAuthenticate
public bool MustAuthenticate(Type type, MethodInfo method)
{
type.ThrowIfNull("type");
method.ThrowIfNull("method");
return method.GetCustomAttributes(typeof(AuthenticateAttribute), false).Any();
}
示例8: CanMapTypeAsync
public async Task<bool> CanMapTypeAsync(HttpContextBase context, Type parameterType)
{
context.ThrowIfNull("context");
parameterType.ThrowIfNull("parameterType");
return await Task.Run(() => _parameterTypeMatchDelegate(parameterType));
}
示例9: CanMapTypeAsync
public override Task<bool> CanMapTypeAsync(HttpContextBase context, Type parameterType)
{
context.ThrowIfNull("context");
parameterType.ThrowIfNull("parameterType");
return parameterType.ImplementsInterface<IConvertible>().AsCompletedTask();
}
示例10: IsNonGenericImplementationOf
public static bool IsNonGenericImplementationOf(this Type type, Type interfaceType)
{
type.ThrowIfNull("type");
interfaceType.ThrowIfNull("interfaceType");
return type.GetInterfaces().Any(interfaceType.Equals);
}
示例11: CanMapTypeAsync
public Task<bool> CanMapTypeAsync(HttpContextBase context, Type parameterType)
{
context.ThrowIfNull("context");
parameterType.ThrowIfNull("parameterType");
return true.AsCompletedTask();
}
示例12: CustomMapperAttribute
public CustomMapperAttribute(Type customMapperType)
{
customMapperType.ThrowIfNull("customMapperType");
if (customMapperType.IsNotPublic)
{
throw new ArgumentException("Type must be public.", "customMapperType");
}
if (customMapperType.IsAbstract)
{
throw new ArgumentException("Type cannot be abstract or static.", "customMapperType");
}
if (!customMapperType.ImplementsInterface<ICustomMapper>())
{
throw new ArgumentException(String.Format("Type must implement {0}.", customMapperType.FullName), "customMapperType");
}
ConstructorInfo constructorInfo = customMapperType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, new Type[0], null);
if (constructorInfo == null)
{
throw new ArgumentException("Type must declare a public default constructor.", "customMapperType");
}
_mapper = (ICustomMapper)Activator.CreateInstance(customMapperType);
}
示例13: CanMapType
public bool CanMapType(HttpRequestBase request, Type parameterType)
{
request.ThrowIfNull("request");
parameterType.ThrowIfNull("parameterType");
return parameterType.ImplementsInterface<IConvertible>();
}
示例14: AspNetDiagnosticConfiguration
public AspNetDiagnosticConfiguration(
Type cacheType,
IEnumerable<Type> requestFilterTypes,
IEnumerable<Type> responseGeneratorTypes,
IEnumerable<Type> responseHandlerTypes,
IEnumerable<Type> errorHandlerTypes,
Type antiCsrfCookieManagerType = null,
Type antiCsrfNonceValidatorType = null,
Type antiCsrfResponseGeneratorType = null)
{
cacheType.ThrowIfNull("cacheType");
requestFilterTypes.ThrowIfNull("requestFilterTypes");
responseGeneratorTypes.ThrowIfNull("responseGeneratorTypes");
responseHandlerTypes.ThrowIfNull("responseHandlerTypes");
errorHandlerTypes.ThrowIfNull("errorHandlerTypes");
_cacheType = cacheType;
_requestFilterTypes = requestFilterTypes.ToArray();
_responseGeneratorTypes = responseGeneratorTypes.ToArray();
_responseHandlerTypes = responseHandlerTypes.ToArray();
_errorHandlerTypes = errorHandlerTypes.ToArray();
_antiCsrfCookieManagerType = antiCsrfCookieManagerType;
_antiCsrfNonceValidatorType = antiCsrfNonceValidatorType;
_antiCsrfResponseGeneratorType = antiCsrfResponseGeneratorType;
}
示例15: Populate
public void Populate(
Type cacheType,
IEnumerable<Type> requestFilterTypes,
IEnumerable<Type> responseGeneratorTypes,
IEnumerable<Type> responseHandlerTypes,
IEnumerable<Type> errorHandlerTypes,
Type antiCsrfCookieManagerType,
Type antiCsrfNonceValidatorType,
Type antiCsrfResponseGeneratorType)
{
cacheType.ThrowIfNull("cacheType");
requestFilterTypes.ThrowIfNull("requestFilterTypes");
responseGeneratorTypes.ThrowIfNull("responseGeneratorTypes");
responseHandlerTypes.ThrowIfNull("responseHandlerTypes");
errorHandlerTypes.ThrowIfNull("errorHandlerTypes");
CacheType = cacheType;
RequestFilterTypes = requestFilterTypes;
ResponseGeneratorTypes = responseGeneratorTypes;
ResponseHandlerTypes = responseHandlerTypes;
ErrorHandlerTypes = errorHandlerTypes;
AntiCsrfCookieManagerType = antiCsrfCookieManagerType;
AntiCsrfNonceValidatorType = antiCsrfNonceValidatorType;
AntiCsrfResponseGeneratorType = antiCsrfResponseGeneratorType;
}