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


C# Type.IsNumeric方法代码示例

本文整理汇总了C#中System.Type.IsNumeric方法的典型用法代码示例。如果您正苦于以下问题:C# Type.IsNumeric方法的具体用法?C# Type.IsNumeric怎么用?C# Type.IsNumeric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Type的用法示例。


在下文中一共展示了Type.IsNumeric方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsNumericPromotion

        private static bool IsNumericPromotion(Type leftType, Type rightType) {
            if (!leftType.IsNumeric() || !rightType.IsNumeric() || leftType.Equals(TypeSystem.Boolean)) {
                return false;
            }

            return true;
        }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:7,代码来源:BinaryNumericPromotionDecision.cs

示例2: IsNumericPromotion

        private static bool IsNumericPromotion(Type type, UnaryOperatorType @operator) {
            if (!type.IsNumeric() ||
                type.Equals(TypeSystem.Boolean) ||
                Array.IndexOf(_unaryOperators, @operator) == -1) {
                return false;
            }

            return true;
        }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:9,代码来源:UnaryNumericPromotionDecision.cs

示例3: BuildJsonObject

 public static IJsonObject BuildJsonObject(Type type, object instance)
 {
     if (type.IsNumeric()) {
         return new NumericJsonProperty(instance);
     }
     if (type == typeof (string)) {
         return new StringJsonProperty(instance);
     }
     if (type.GetInterface("IEnumerable") != null) {
         return new JsonArray((IEnumerable)instance);
     }
     return new JsonClass(instance);
 }
开发者ID:pierregillon,项目名称:ConnectUs,代码行数:13,代码来源:JsonObjectFactory.cs

示例4: GetODSType

 private static string GetODSType(Type type)
 {
     if (type == typeof(DateTime) || type == typeof(DateTime?))
     {
         return OfficeValueTypes.Date;
     }
     if (type == typeof(bool) || type == typeof(bool?))
     {
         return OfficeValueTypes.Boolean;
     }
     if (type.IsNumeric())
     {
         return OfficeValueTypes.Float;
     }
     return OfficeValueTypes.String;
 }
开发者ID:guidgets,项目名称:XamlGrid,代码行数:16,代码来源:ODSExporter.cs

示例5: GetCoarseType

        public static string GetCoarseType(Type type)
        {
            if (type.IsDateTime())
                return "datetime";
            if (type.IsNumeric())
                return "numeric";
            if (type.IsString())
                return "string";
            if (type.IsBool())
                return "bool";
            if (type.IsGuid())
                return "guid";

            return "complex";
        }
开发者ID:Batierk,项目名称:ExpressiveAnnotations,代码行数:15,代码来源:Helper.cs

示例6: GetCoarseType

        public static string GetCoarseType(Type type)
        {
            if (type.IsTimeSpan())
                return "timespan";
            if (type.IsDateTime())
                return "datetime";
            if (type.IsNumeric())
                return "numeric";
            if (type.IsString())
                return "string";
            if (type.IsBool())
                return "bool";
            if (type.IsGuid())
                return "guid";

            return "object";
        }
开发者ID:wenyanw,项目名称:ExpressiveAnnotations,代码行数:17,代码来源:Helper.cs

示例7: GetCoarseType

        public static string GetCoarseType(Type type)
        {
            if (type.IsTimeSpan())
                return "timespan";
            if (type.IsDateTime())
                return "datetime";
            if (type.IsNumeric())
                return "numeric";
            if (type.IsString())
                return "string";
            if (type.IsBool())
                return "bool";
            if (type.IsGuid())
                return "guid";

            type = type.IsNullable() ? Nullable.GetUnderlyingType(type) : type;
            return type.Name.ToLowerInvariant();
        }
开发者ID:revocengiz,项目名称:ExpressiveAnnotations,代码行数:18,代码来源:Helper.cs

示例8: Convert

        /// <summary>
        /// Convert the string representation to the destination type
        /// </summary>
        /// <param name="input">Input string</param>
        /// <param name="destinationType">Destination type</param>
        /// <param name="context">Current context</param>
        /// <returns>Converted object of the destination type</returns>
        public object Convert(string input, Type destinationType, BindingContext context)
        {
            var converter = TypeDescriptor.GetConverter(destinationType);

            if (!converter.CanConvertFrom(typeof(string)) || (destinationType.IsNumeric() && string.IsNullOrEmpty(input)))
            {
                return null;
            }

            try
            {
                return converter.ConvertFrom(input);
            }
            catch (FormatException)
            {
                if (destinationType == typeof(bool) && converter.GetType() == typeof(BooleanConverter) && "on".Equals(input, StringComparison.OrdinalIgnoreCase))
                {
                    return true;
                }
                return null;
            }
        }
开发者ID:wtilton,项目名称:Nancy,代码行数:29,代码来源:FallbackConverter.cs

示例9: Emit

 /// <summary>
 /// 写入类型转换的 IL 指令。
 /// </summary>
 /// <param name="generator">IL 的指令生成器。</param>
 /// <param name="inputType">要转换的对象的类型。</param>
 /// <param name="outputType">要将输入对象转换到的类型。</param>
 /// <param name="isChecked">是否执行溢出检查。</param>
 public override void Emit(ILGenerator generator, Type inputType, Type outputType, bool isChecked)
 {
     Contract.Assume((inputType == typeof(decimal) && outputType.IsNumeric()) ||
         (outputType == typeof(decimal) && inputType.IsNumeric()));
     MethodInfo method;
     if (inputType == typeof(decimal))
     {
         if (outputType.IsEnum)
         {
             outputType = Enum.GetUnderlyingType(outputType);
         }
         method = UserConversionCache.GetConversionTo(inputType, outputType);
     }
     else
     {
         if (inputType.IsEnum)
         {
             inputType = Enum.GetUnderlyingType(inputType);
         }
         method = UserConversionCache.GetConversionFrom(outputType, inputType);
     }
     generator.EmitCall(method);
 }
开发者ID:GISwilson,项目名称:Cyjb,代码行数:30,代码来源:DecimalConversion.cs

示例10: TypesArePrimitiveAndConvertible

        private bool TypesArePrimitiveAndConvertible(Type source, Type dest) {
            Type nonNullableSourceType = source.GetNonNullableType();
            Type nonNullableDestinationType = dest.GetNonNullableType();

            return (!(source.IsEnum || dest.IsEnum)) && (source.IsEquivalentTo(dest) || ((source.IsNullableType() && dest.IsEquivalentTo(nonNullableSourceType)) || ((dest.IsNullableType() && source.IsEquivalentTo(nonNullableDestinationType)) ||
                   ((source.IsNumeric() && dest.IsNumeric()) && (nonNullableDestinationType != TypeSystem.Boolean)))));
        }
开发者ID:sagifogel,项目名称:NJection.LambdaConverter,代码行数:7,代码来源:Binary.cs

示例11: CanConvertTo

 /// <summary>
 /// Whether the converter can convert to the destination type
 /// </summary>
 /// <param name="destinationType">Destination type</param>
 /// <param name="context">The current binding context</param>
 /// <returns>True if conversion supported, false otherwise</returns>
 public bool CanConvertTo(Type destinationType, BindingContext context)
 {
     return destinationType.IsNumeric();
 }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:10,代码来源:NumericConverter.cs

示例12: GetBetweenValueTypeConversion

 /// <summary>
 /// 返回从值类型转换为值类型的类型转换。
 /// </summary>
 /// <param name="inputType">要转换的对象的类型。</param>
 /// <param name="outputType">要将输入对象转换到的类型。</param>
 /// <returns>从值类型转换为值类型的类型转换,如果不存在则为 <c>null</c>。</returns>
 private static Conversion GetBetweenValueTypeConversion(Type inputType, Type outputType)
 {
     Contract.Requires(inputType != null && outputType != null);
     Contract.Requires(inputType.IsValueType && outputType.IsValueType);
     TypeCode inputTypeCode = Type.GetTypeCode(inputType);
     TypeCode outputTypeCode = Type.GetTypeCode(outputType);
     // 数值或枚举转换。
     if (inputTypeCode.IsNumeric() && outputTypeCode.IsNumeric())
     {
         return GetNumericOrEnumConversion(inputType, inputTypeCode, outputType, outputTypeCode);
     }
     // 可空类型转换。
     Type inputUnderlyingType = Nullable.GetUnderlyingType(inputType);
     Type outputUnderlyingType = Nullable.GetUnderlyingType(outputType);
     if (inputUnderlyingType != null)
     {
         inputTypeCode = Type.GetTypeCode(inputUnderlyingType);
         if (outputUnderlyingType == null)
         {
             // 可空类型 S? 到非可空值类型 T 的转换。
             // 1. 可空类型为 null,引发异常。
             // 2. 将可空类型解包
             // 3. 执行从 S 到 T 的预定义类型转换。
             // 这里 S 和 T 都是值类型,可能的预定义类型转换只有标识转换和数值转换。
             if (inputUnderlyingType == outputType ||
                 (inputTypeCode.IsNumeric() && outputTypeCode.IsNumeric()))
             {
                 return FromNullableConversion.Default;
             }
             return null;
         }
         outputTypeCode = Type.GetTypeCode(outputUnderlyingType);
         // 可空类型间转换,从 S? 到 T?,与上面同理,但此时不可能有 S==T。
         if (inputTypeCode.IsNumeric() && outputTypeCode.IsNumeric())
         {
             Conversion conversion = GetNumericOrEnumConversion(inputUnderlyingType, inputTypeCode,
                 outputUnderlyingType, outputTypeCode);
             return conversion.ConversionType.IsImplicit()
                 ? BetweenNullableConversion.Implicit : BetweenNullableConversion.Explicit;
         }
         return null;
     }
     if (outputUnderlyingType != null)
     {
         // 非可空类型到可空类型转换,与上面同理。
         if (inputType == outputUnderlyingType)
         {
             return ToNullableConversion.Implicit;
         }
         outputTypeCode = Type.GetTypeCode(outputUnderlyingType);
         if (inputType.IsNumeric() && outputTypeCode.IsNumeric())
         {
             Conversion conversion = GetNumericOrEnumConversion(inputType, inputTypeCode,
                 outputUnderlyingType, outputTypeCode);
             return conversion.ConversionType.IsImplicit() ?
                 ToNullableConversion.Implicit : ToNullableConversion.Explicit;
         }
     }
     return null;
 }
开发者ID:GISwilson,项目名称:Cyjb,代码行数:66,代码来源:ConversionFactory.cs

示例13: CanMatchType

 public override bool CanMatchType(Type requestedType)
 {
     return requestedType == null || requestedType.IsNumeric() || requestedType.GetTypeCode() == TypeCode.Boolean;
 }
开发者ID:GAIPS-INESC-ID,项目名称:FAtiMA-Toolkit,代码行数:4,代码来源:PrimitiveGraphNode.cs

示例14: TryChangeType

        internal bool TryChangeType(ref object value, Type type)
        {
            if (type != null && type != typeof(object))
            {
                // handle nullable types
                if (type.IsNullableType())
                {
                    // if value is null, we're done
                    if (value == null || object.Equals(value, string.Empty))
                    {
                        value = null;
                        return true;
                    }

                    // get actual type for parsing
                    type = Nullable.GetUnderlyingType(type);
                }
                else if (type.GetTypeInfo().IsValueType && value == null)
                {
                    // not nullable, can't assign null value to this
                    return false;
                }

                // handle special numeric formatting
                var ci = GetCultureInfo();
                var str = value as string;
                if (!string.IsNullOrEmpty(str) && type.IsNumeric())
                {
                    // handle percentages (ci.NumberFormat.PercentSymbol? overkill...)
                    bool pct = str[0] == '%' || str[str.Length - 1] == '%';
                    if (pct)
                    {
                        str = str.Trim('%');
                    }
                    decimal d;
                    if (decimal.TryParse(str, NumberStyles.Any, ci, out d))
                    {
                        if (pct)
                        {
                            value = d / 100;
                        }
                        else
                        {
                            // <<IP>> for currencies Convert.ChangeType will always give exception if we do without parsing,
                            // so change value here to the parsed one
                            value = d;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }

                // ready to change type
                try
                {
                    value = Convert.ChangeType(value, type, ci);
                }
                catch
                {
                    return false;
                }
            }
            return true;
        }
开发者ID:GJian,项目名称:UWP-master,代码行数:66,代码来源:DataGrid.cs

示例15: CreateFieldFrom

		/// <summary>
		/// Creates a field that will contain a value of a specific type
		/// <para xml:lang="es">
		/// Crea un campo que contendra un valor de un tipo especifico.
		/// </para>
		/// </summary>
		public static FormField CreateFieldFrom(Type type)
		{
			//validate arguments
			if (type == null) throw new ArgumentNullException("type");

			//field
			FormField field;

			//Enum
			if (type.GetTypeInfo().IsEnum)
			{
				field = new EnumField(type);
			}

			//Type, ignore this since we can't know if type means Person (as in a serializable object) or typeof(Person) as a type which child types you would choose from
			//else if (type.Equals(typeof(Type)))
			//{
			//	field = new TypeField();
			//}

			//Bool
			else if (type.Equals(typeof(bool)))
			{
				field = new BoolField();
			}

			//DateTime
			else if (type.Equals(typeof(DateTime)))
			{
				field = new DateTimeField();
			}

			//Numeric
			else if (type.IsNumeric())
			{
				if (type.IsIntegral())
				{
					field = new IntegerField();
				}
				else
				{
					field = new DecimalField();
				}
			}

			//String serializable
			else if (type.GetTypeInfo().ImplementedInterfaces.Contains(typeof(Data.IStringSerializable)))
			{
				field = new StringSerializableField(type);
			}

			//XML
			else if (type.GetTypeInfo().ImplementedInterfaces.Contains(typeof(System.Xml.Serialization.IXmlSerializable)))
			{
				field = new XmlSerializableField(type);
			}

			//String
			else if (type.Equals(typeof(string)))
			{
				field = new StringField();
			}

			//byte[]
			else if (type.Equals(typeof(byte[])))
			{
				field = new BinaryField();
			}

			//otherwise just create a textbox
			else
			{
				field = new StringField();
			}

			//return
			return field;
		}
开发者ID:okhosting,项目名称:OKHOSTING.UI,代码行数:84,代码来源:FormField.cs


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