当前位置: 首页>>代码示例>>C#>>正文


C# MethodInfo.ThrowIfNull方法代码示例

本文整理汇总了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);
		}
开发者ID:nathan-alden,项目名称:junior-route,代码行数:25,代码来源:ModelMapper.cs

示例2: Map

        public IdResult Map(Type type, MethodInfo method)
        {
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");

            return IdResult.IdMapped(_guidFactory.Random());
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:7,代码来源:RandomIdMapper.cs

示例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();
		}
开发者ID:nathan-alden,项目名称:junior-route,代码行数:27,代码来源:JsonModelMapper.cs

示例4: MustAuthenticateAsync

        public Task<bool> MustAuthenticateAsync(Type type, MethodInfo method)
        {
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");

            return method.GetCustomAttributes(typeof(AuthenticateAttribute), false).Any().AsCompletedTask();
        }
开发者ID:nathan-alden,项目名称:junior-route,代码行数:7,代码来源:AuthenticateAttributeStrategy.cs

示例5: MustAuthenticate

        public bool MustAuthenticate(Type type, MethodInfo method)
        {
            type.ThrowIfNull("type");
            method.ThrowIfNull("method");

            return method.GetCustomAttributes(typeof(AuthenticateAttribute), false).Any();
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:7,代码来源:AuthenticateAttributeStrategy.cs

示例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;
		}
开发者ID:nathan-alden,项目名称:junior-route,代码行数:58,代码来源:ParameterValueRetriever.cs

示例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();
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:9,代码来源:NoContentMapper.cs

示例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();
        }
开发者ID:nathan-alden,项目名称:junior-route,代码行数:9,代码来源:HttpServerUtilityBaseMapper.cs

示例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();
        }
开发者ID:nathan-alden,项目名称:junior-route,代码行数:9,代码来源:NameAttributeMapper.cs

示例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();
        }
开发者ID:nathan-alden,项目名称:junior-route,代码行数:9,代码来源:IdAttributeMapper.cs

示例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());
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:9,代码来源:DefaultValueMapper.cs

示例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;
 }
开发者ID:msusur,项目名称:Crowfx,代码行数:10,代码来源:BusinessControllerBase.cs

示例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();
        }
开发者ID:dblchu,项目名称:JuniorRoute,代码行数:11,代码来源:ResolvedRelativeUrlAttributeMapper.cs

示例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();
        }
开发者ID:nathan-alden,项目名称:junior-route,代码行数:11,代码来源:NoContentMapper.cs

示例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);
            }
        }
开发者ID:nathan-alden,项目名称:junior-route,代码行数:14,代码来源:RelativeUrlResolversFromAttributesMapper.cs


注:本文中的System.Reflection.MethodInfo.ThrowIfNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。