コード例 #1
0
        public static IType Create(DataType oDataType, string sValue, string sFormat, IFormatProvider oIFormatProvider)
        {
            IType oIType;

            if (string.IsNullOrEmpty(sValue))
            {
                oIType = Empty(oDataType);
            }
            else
            {
                switch (oDataType.m_oKind)
                {
                case Kind.Boolean:
                    oIType = new BooleanType(sValue, oIFormatProvider);
                    break;

                case Kind.Currency:
                    oIType = new CurrencyType(sValue, oIFormatProvider);
                    break;

                case Kind.Date:
                    oIType = new DateType(sValue, sFormat, oIFormatProvider);
                    break;

                case Kind.DateTime:
                    oIType = new DateTimeType(sValue, sFormat, oIFormatProvider);
                    break;

                case Kind.Decimal:
                    oIType = new DecimalType(sValue, oIFormatProvider);
                    break;

                case Kind.Double:
                    oIType = new DoubleType(sValue, oIFormatProvider);
                    break;

                case Kind.Int16:
                    oIType = new Int16Type(sValue, oIFormatProvider);
                    break;

                case Kind.Int32:
                    oIType = new Int32Type(sValue, oIFormatProvider);
                    break;

                case Kind.Int64:
                    oIType = new Int64Type(sValue, oIFormatProvider);
                    break;

                case Kind.Single:
                    oIType = new SingleType(sValue, oIFormatProvider);
                    break;

                case Kind.String:
                    oIType = new StringType(sValue);
                    break;

                case Kind.Text:
                    oIType = new TextType(sValue);
                    break;

                default:
                    throw new ArgumentException(string.Format("Invalid type {0} specified", oDataType));
                }
            }
            return(oIType);
        }
コード例 #2
0
        public static IType Create(IConvertible oIConvertible, IFormatProvider oIFormatProvider)
        {
            IType oIType;

            switch (oIConvertible.GetTypeCode())
            {
            case TypeCode.Boolean:
                oIType = new BooleanType(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.Byte:
                oIType = new Int16Type(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.Char:
                oIType = new StringType(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.DateTime:
                oIType = new DateTimeType(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.DBNull:
                oIType = DataType.Empty(DataType.None);
                break;

            case TypeCode.Decimal:
                oIType = new DecimalType(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.Double:
                oIType = new DoubleType(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.Int16:
                oIType = new Int16Type(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.Int32:
                oIType = new Int32Type(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.Int64:
                oIType = new Int64Type(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.Object:
                oIType = oIConvertible as IType ?? new StringType(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.SByte:
                oIType = new Int16Type(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.Single:
                oIType = new SingleType(oIConvertible, oIFormatProvider);
                break;

            case TypeCode.String:
                oIType = new StringType(oIConvertible, oIFormatProvider);
                break;

            default:
                throw new ArgumentException(string.Format("Invalid value type {0} specified", oIConvertible.GetType()));
            }
            return(oIType);
        }