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


C# TypeCode.ToString方法代码示例

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


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

示例1: ComparisonAssertion

        public ComparisonAssertion(Predicate<int> predicate, IContextExpression source, TypeCode type, string value)
            : base(source)
        {
            if (predicate == null)
                throw new ArgumentNullException("predicate");

            _predicate = predicate;

            if (type == TypeCode.DBNull
                || type == TypeCode.Empty
                || type == TypeCode.Object)
            {
                string message = string.Format(
                    "The {0} value type is invalid for a comparison.", type.ToString());
                throw new ArgumentException(message, "type");
            }

            //
            // Convert the expected value to the comparison type and
            // save it as a field.
            //

            _expectedValue = Convert.ChangeType(value, type/*, FIXME CultureInfo.InvariantCulture */);
        }
开发者ID:stewart-rae,项目名称:Elmah,代码行数:24,代码来源:ComparisonAssertion.cs

示例2: GetDefaultColumnType

 public static void GetDefaultColumnType(TypeCode nativeTypeCode, bool nullable, DbfVersion version, out ColumnType type, out int defaultWidth, out int defaultDecimals)
 {
     defaultDecimals = 0; // default
     if (version == DbfVersion.DbfDotNet)
     {
         switch (nativeTypeCode)
         {
             case TypeCode.Boolean:
                 type = ColumnType.LOGICAL;
                 defaultWidth = 1;
                 break;
             case TypeCode.Byte:
                 type = ColumnType.BYTE;
                 defaultWidth = 1;
                 break;
             case TypeCode.SByte:
                 type = ColumnType.SBYTE;
                 defaultWidth = 1;
                 break;
             case TypeCode.Int16:
                 type = ColumnType.INT16;
                 defaultWidth = 2;
                 break;
             case TypeCode.UInt16:
                 type = ColumnType.UINT16;
                 defaultWidth = 2;
                 break;
             case TypeCode.Int32:
                 type = ColumnType.INT32;
                 defaultWidth = 4;
                 break;
             case TypeCode.UInt32:
                 type = ColumnType.UINT32;
                 defaultWidth = 4;
                 break;
             case TypeCode.Single:
                 type = ColumnType.SINGLE;
                 defaultWidth = 4;
                 break;
             case TypeCode.Int64:
                 type = ColumnType.INT64;
                 defaultWidth = 8;
                 break;
             case TypeCode.UInt64:
                 type = ColumnType.UINT64;
                 defaultWidth = 8;
                 break;
             case TypeCode.Double:
                 type = ColumnType.DOUBLE;
                 defaultWidth = 8;
                 break;
             case TypeCode.Decimal:
                 type = ColumnType.DECIMAL;
                 defaultWidth = 13;// 96 bits + 0..28 (4 bits exponent) + sign = 101 bits minimum
                 break;
             case TypeCode.DateTime:
                 type = ColumnType.DATETIME;
                 defaultWidth = 8; // 64 bits
                 break;
             case TypeCode.String:
                 type = ColumnType.CHARACTER;
                 defaultWidth = 20; // unknown
                 break;
             case TypeCode.Char:
                 // TODO depend on the encoding
                 type = ColumnType.CHARW;
                 defaultWidth = 2;
                 break;
             default:
                 throw new InvalidColumnException(nativeTypeCode.ToString(), null);
         }
     }
     else
     {
         switch (nativeTypeCode)
         {
             case TypeCode.Boolean:
                 type = ColumnType.LOGICAL;
                 defaultWidth = 1; // T or F
                 break;
             case TypeCode.Byte:
                 type = ColumnType.NUMERICAL;
                 defaultWidth = 3; // 255
                 break;
             case TypeCode.SByte:
                 type = ColumnType.NUMERICAL;
                 defaultWidth = 4; // -128
                 break;
             case TypeCode.Int16:
                 type = ColumnType.NUMERICAL;
                 defaultWidth = 6; // -32768
                 break;
             case TypeCode.UInt16:
                 type = ColumnType.NUMERICAL;
                 defaultWidth = 5; // 65535
                 break;
             case TypeCode.Int32:
                 type = ColumnType.NUMERICAL;
                 defaultWidth = 11; // -2147483648
                 break;
//.........这里部分代码省略.........
开发者ID:KillerGoldFisch,项目名称:GCharp,代码行数:101,代码来源:ColumnDefinition.cs

示例3: GetMonoType

	static string GetMonoType (TypeCode tc)
	{
		//see mcs/class/corlib/System/TypeCode.cs
		//see mono/mono/dis/get.c

		switch (tc)
		{
			case TypeCode.Int32:
				return "int";

			case TypeCode.String:
				return "string";

			default: //TODO: construct signature based on mono docs
				return tc.ToString ().ToLower ();
		}
	}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:17,代码来源:cilc.cs

示例4: GetType

        public IType GetType(TypeCode typeCode)
        {
            switch (typeCode) {
            case TypeCode.Empty:
                return GetType(typeof(void));

            case TypeCode.Object:
                return GetType(typeof(object));

            case TypeCode.DBNull:
                return GetType(typeof(DBNull));

            case TypeCode.Boolean:
                return GetType(typeof(bool));

            case TypeCode.Char:
                return GetType(typeof(char));

            case TypeCode.SByte:
                return GetType(typeof(sbyte));

            case TypeCode.Byte:
                return GetType(typeof(byte));

            case TypeCode.Int16:
                return GetType(typeof(short));

            case TypeCode.UInt16:
                return GetType(typeof(ushort));

            case TypeCode.Int32:
                return GetType(typeof(int));

            case TypeCode.UInt32:
                return GetType(typeof(uint));

            case TypeCode.Int64:
                return GetType(typeof(long));

            case TypeCode.UInt64:
                return GetType(typeof(ulong));

            case TypeCode.Single:
                return GetType(typeof(float));

            case TypeCode.Double:
                return GetType(typeof(double));

            case TypeCode.Decimal:
                return GetType(typeof(decimal));

            case TypeCode.DateTime:
                return GetType(typeof(DateTime));

            case TypeCode.String:
                return GetType(typeof(string));
            }

            throw new KeyNotFoundException(typeCode.ToString());
        }
开发者ID:irdc,项目名称:PoundWise,代码行数:60,代码来源:ReflectionTypeProvider.cs

示例5: NumericPromotionOpcodeFor

 private static OpCode NumericPromotionOpcodeFor(TypeCode typeCode, bool @checked)
 {
     switch (typeCode)
     {
         case TypeCode.SByte:
             return @checked ? OpCodes.Conv_Ovf_I1 : OpCodes.Conv_I1;
         case TypeCode.Byte:
             return @checked ? OpCodes.Conv_Ovf_U1 : OpCodes.Conv_U1;
         case TypeCode.Int16:
             return @checked ? OpCodes.Conv_Ovf_I2 : OpCodes.Conv_I2;
         case TypeCode.UInt16:
         case TypeCode.Char:
             return @checked ? OpCodes.Conv_Ovf_U2 : OpCodes.Conv_U2;
         case TypeCode.Int32:
             return @checked ? OpCodes.Conv_Ovf_I4 : OpCodes.Conv_I4;
         case TypeCode.UInt32:
             return @checked ? OpCodes.Conv_Ovf_U4 : OpCodes.Conv_U4;
         case TypeCode.Int64:
             return @checked ? OpCodes.Conv_Ovf_I8 : OpCodes.Conv_I8;
         case TypeCode.UInt64:
             return @checked ? OpCodes.Conv_Ovf_U8 : OpCodes.Conv_U8;
         case TypeCode.Single:
             return OpCodes.Conv_R4;
         case TypeCode.Double:
             return OpCodes.Conv_R8;
         default:
             throw new ArgumentException(typeCode.ToString());
     }
 }
开发者ID:Bombadil77,项目名称:boo,代码行数:29,代码来源:EmitAssembly.cs

示例6: InvalidDataType

 internal static ArgumentException InvalidDataType(TypeCode typecode)
 {
     return Argument(System.Data.Res.GetString("ADP_InvalidDataType", new object[] { typecode.ToString() }));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:4,代码来源:ADP.cs

示例7: TestEvalSuccess

        public static void TestEvalSuccess(string input, TypeCode resultCode, object resultValue, object thisArray, Language language)
        {
            Eval eval = new Eval(input, language);
            EvalResult result = eval.Evaluate(thisArray);

            if ((resultCode != result.Type) ||                             
                ((resultValue == null) && (result.Value != null)) ||       
                ((result.Value != null) && (Type.GetTypeCode(resultValue.GetType()) != resultCode)))   
                throw new ApplicationException("Eval result type incorrect. Expected '" + resultCode.ToString() + "' but received '" + result.Type.ToString() + "' for input string '" + input + "'.");
            else
            {
                // Check result specific value
                switch (resultCode)
                {
                    case TypeCode.Boolean:
                        if ((Boolean)resultValue == (Boolean)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Byte:
                        if ((Byte)resultValue == (Byte)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Char:
                        if ((Char)resultValue == (Char)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.DateTime:
                        if ((DateTime)resultValue == (DateTime)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.DBNull:
                        if ((DBNull)resultValue == (DBNull)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Decimal:
                        if ((Decimal)resultValue == (Decimal)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Double:
                        if ((Double)resultValue == (Double)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Empty:
                        if (resultValue == null)
                            return;
                        else
                            break;
                    case TypeCode.Int16:
                        if ((Int16)resultValue == (Int16)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Int32:
                        if ((Int32)resultValue == (Int32)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Int64:
                        if ((Int64)resultValue == (Int64)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Object:
                        if (resultValue == result.Value)
                            return;
                        else
                            break;
                    case TypeCode.SByte:
                        if ((SByte)resultValue == (SByte)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.Single:
                        if ((Single)resultValue == (Single)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.String:
                        if ((String)resultValue == (String)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.UInt16:
                        if ((UInt16)resultValue == (UInt16)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.UInt32:
                        if ((UInt32)resultValue == (UInt32)result.Value)
                            return;
                        else
                            break;
                    case TypeCode.UInt64:
//.........这里部分代码省略.........
开发者ID:ComponentFactory,项目名称:Quicksilver,代码行数:101,代码来源:UnitTestEval.cs

示例8: InvalidDataTypeForValue

 internal static Exception InvalidDataTypeForValue(Type dataType, TypeCode tc)
 {
     return Argument(System.Data.OracleClient.Res.GetString("ADP_InvalidDataTypeForValue", new object[] { dataType.ToString(), tc.ToString() }));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:4,代码来源:ADP.cs

示例9: UnknownDataTypeCode

 internal static Exception UnknownDataTypeCode(Type dataType, TypeCode tc)
 {
     return Simple(System.Data.OracleClient.Res.GetString("ADP_UnknownDataTypeCode", new object[] { dataType.ToString(), tc.ToString() }));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:4,代码来源:ADP.cs

示例10: ConvertTo

        /// <summary>
        /// Implicit conversion from incoming value to target type.
        /// </summary>
        /// <param name="target">Target type for value to be converted into.</param>
        /// <param name="value">Value to be converted.</param>
        /// <param name="language">Language rules to be used.</param>
        /// <returns>Boxed version of target type.</returns>
        public static object ConvertTo(TypeCode target, object value, Language language)
        {
            if (value == null)
            {
                if (target == TypeCode.Object)
                    return value;
            }
            else
            {
                // If the value is already the same target type then we are done
                if (Type.GetTypeCode(value.GetType()) == target)
                    return value;
                else
                {
                    // Perform implicit conversion for the types where it is possible
                    switch (target)
                    {
                        case TypeCode.String:
                            return value.ToString();
                        case TypeCode.Boolean:
                            return ConvertToBoolean(value, language);
                        case TypeCode.Char:
                            return ConvertToChar(value, language);
                        case TypeCode.SByte:
                            return ConvertToSByte(value, language);
                        case TypeCode.Byte:
                            return ConvertToByte(value, language);
                        case TypeCode.Int16:
                            return ConvertToInt16(value, language);
                        case TypeCode.UInt16:
                            return ConvertToUInt16(value, language);
                        case TypeCode.Int32:
                            return ConvertToInt32(value, language);
                        case TypeCode.UInt32:
                            return ConvertToUInt32(value, language);
                        case TypeCode.Int64:
                            return ConvertToInt64(value, language);
                        case TypeCode.UInt64:
                            return ConvertToUInt64(value, language);
                        case TypeCode.Single:
                            return ConvertToSingle(value, language);
                        case TypeCode.Double:
                            return ConvertToDouble(value, language);
                        case TypeCode.Decimal:
                            return ConvertToDecimal(value, language);
                        case TypeCode.Object:
                            return value;
                    }
                }
            }

            throw new ArgumentException("Cannot perform implicit conversion from incoming '" + Type.GetTypeCode(value.GetType()).ToString() + "' to '" + target.ToString() + "'.");
        }
开发者ID:ComponentFactory,项目名称:Quicksilver,代码行数:60,代码来源:ImplicitConvert.cs


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