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


C# PropertyInfo.ThrowIfNull方法代码示例

本文整理汇总了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();
		}
开发者ID:kelong,项目名称:JuniorRoute,代码行数:8,代码来源:DefaultValueMapper.cs

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

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

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


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