コード例 #1
0
ファイル: DoubleType.cs プロジェクト: ysc0423/CommonCore
        internal static bool TryParse(string Value, ref double Result)
        {
            CultureInfo      cultureInfo            = Utils.GetCultureInfo();
            NumberFormatInfo numberFormat           = cultureInfo.NumberFormat;
            NumberFormatInfo normalizedNumberFormat = DecimalType.GetNormalizedNumberFormat(numberFormat);

            Value = Utils.ToHalfwidthNumbers(Value, cultureInfo);
            if (numberFormat == normalizedNumberFormat)
            {
                return(double.TryParse(Value, NumberStyles.Any, (IFormatProvider)normalizedNumberFormat, out Result));
            }
            try
            {
                Result = double.Parse(Value, NumberStyles.Any, (IFormatProvider)normalizedNumberFormat);
                return(true);
            }
            catch (FormatException ex1)
            {
                try
                {
                    return(double.TryParse(Value, NumberStyles.Any, (IFormatProvider)numberFormat, out Result));
                }
                catch (ArgumentException ex2)
                {
                    return(false);
                }
            }
            catch (StackOverflowException ex)
            {
                throw ex;
            }
            catch (OutOfMemoryException ex)
            {
                throw ex;
            }
            catch (ThreadAbortException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: DecimalType.cs プロジェクト: ysc0423/CommonCore
        /// <summary>Returns a <see langword="Decimal" /> value that corresponds to the specified object and number format information. </summary>
        /// <param name="Value">Required. Object to convert to a <see langword="Decimal" /> value.</param>
        /// <param name="NumberFormat">A <see cref="T:System.Globalization.NumberFormatInfo" /> object that defines how numeric values are formatted and displayed, depending on the culture.</param>
        /// <returns>The <see langword="Decimal" /> value that corresponds to <paramref name="Value" />.</returns>
        public static Decimal FromObject(object Value, NumberFormatInfo NumberFormat)
        {
            if (Value == null)
            {
                return(Decimal.Zero);
            }
            IConvertible convertible = Value as IConvertible;

            if (convertible != null)
            {
                switch (convertible.GetTypeCode())
                {
                case TypeCode.Boolean:
                    return(DecimalType.FromBoolean(convertible.ToBoolean((IFormatProvider)null)));

                case TypeCode.Byte:
                    return(new Decimal((int)convertible.ToByte((IFormatProvider)null)));

                case TypeCode.Int16:
                    return(new Decimal((int)convertible.ToInt16((IFormatProvider)null)));

                case TypeCode.Int32:
                    return(new Decimal(convertible.ToInt32((IFormatProvider)null)));

                case TypeCode.Int64:
                    return(new Decimal(convertible.ToInt64((IFormatProvider)null)));

                case TypeCode.Single:
                    return(new Decimal(convertible.ToSingle((IFormatProvider)null)));

                case TypeCode.Double:
                    return(new Decimal(convertible.ToDouble((IFormatProvider)null)));

                case TypeCode.Decimal:
                    return(convertible.ToDecimal((IFormatProvider)null));

                case TypeCode.String:
                    return(DecimalType.FromString(convertible.ToString((IFormatProvider)null), NumberFormat));
                }
            }
            throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromTo", Utils.VBFriendlyName(Value), "Decimal"));
        }
コード例 #3
0
 /// <summary>Returns a <see langword="Long" /> value that corresponds to the specified string. </summary>
 /// <param name="Value">Required. String to convert to a <see langword="Long" /> value.</param>
 /// <returns>The <see langword="Long" /> value that corresponds to <paramref name="Value" />.</returns>
 public static long FromString(string Value)
 {
     if (Value == null)
     {
         return(0);
     }
     try
     {
         long i64Value = 0;
         if (Utils.IsHexOrOctValue(Value, ref i64Value))
         {
             return(i64Value);
         }
         return(Convert.ToInt64(DecimalType.Parse(Value, (NumberFormatInfo)null)));
     }
     catch (FormatException ex)
     {
         throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromStringTo", Strings.Left(Value, 32), "Long"), (Exception)ex);
     }
 }
コード例 #4
0
ファイル: DoubleType.cs プロジェクト: ysc0423/CommonCore
        /// <summary>Returns a <see langword="Double" /> value that corresponds to the specified string and number format information. </summary>
        /// <param name="Value">Required. String to convert to a <see langword="Double" /> value.</param>
        /// <param name="NumberFormat">A <see cref="T:System.Globalization.NumberFormatInfo" /> object that defines how numeric values are formatted and displayed, depending on the culture.</param>
        /// <returns>The <see langword="Double" /> value corresponding to <paramref name="Value" />.</returns>
        public static double Parse(string Value, NumberFormatInfo NumberFormat)
        {
            CultureInfo cultureInfo = Utils.GetCultureInfo();

            if (NumberFormat == null)
            {
                NumberFormat = cultureInfo.NumberFormat;
            }
            NumberFormatInfo normalizedNumberFormat = DecimalType.GetNormalizedNumberFormat(NumberFormat);

            Value = Utils.ToHalfwidthNumbers(Value, cultureInfo);
            try
            {
                return(double.Parse(Value, NumberStyles.Any, (IFormatProvider)normalizedNumberFormat));
            }
            catch (FormatException ex) when(NumberFormat != normalizedNumberFormat)
            {
                return(double.Parse(Value, NumberStyles.Any, (IFormatProvider)NumberFormat));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #5
0
ファイル: DecimalType.cs プロジェクト: ysc0423/CommonCore
 /// <summary>Returns a <see langword="Decimal" /> value that corresponds to the specified string and number format information. </summary>
 /// <param name="Value">Required. String to convert to a <see langword="Decimal" /> value.</param>
 /// <param name="NumberFormat">A <see cref="T:System.Globalization.NumberFormatInfo" /> object that defines how numeric values are formatted and displayed, depending on the culture.</param>
 /// <returns>The <see langword="Decimal" /> value that corresponds to <paramref name="Value" />.</returns>
 public static Decimal FromString(string Value, NumberFormatInfo NumberFormat)
 {
     if (Value == null)
     {
         return(Decimal.Zero);
     }
     try
     {
         long i64Value = 0;
         if (Utils.IsHexOrOctValue(Value, ref i64Value))
         {
             return(new Decimal(i64Value));
         }
         return(DecimalType.Parse(Value, NumberFormat));
     }
     catch (OverflowException ex)
     {
         throw ExceptionUtils.VbMakeException(6);
     }
     catch (FormatException ex)
     {
         throw new InvalidCastException(Utils.GetResourceString("InvalidCast_FromStringTo", Strings.Left(Value, 32), "Decimal"));
     }
 }
コード例 #6
0
ファイル: VB6RandomFile.cs プロジェクト: ysc0423/CommonCore
        internal override void PutObject(object Value, long RecordNumber = 0, bool ContainedInVariant = true)
        {
            this.ValidateWriteable();
            if (Value == null)
            {
                this.PutEmpty(RecordNumber);
            }
            else
            {
                Type type = Value.GetType();
                if (type == null)
                {
                    throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedIOType1", new string[1]
                    {
                        "Empty"
                    })), 5);
                }
                if (type.IsArray)
                {
                    this.PutDynamicArray(RecordNumber, (Array)Value, true, -1);
                }
                else
                {
                    if (type.IsEnum)
                    {
                        type = Enum.GetUnderlyingType(type);
                    }
                    switch (Type.GetTypeCode(type))
                    {
                    case TypeCode.DBNull:
                        this.PutShort(RecordNumber, (short)1, false);
                        break;

                    case TypeCode.Boolean:
                        this.PutBoolean(RecordNumber, BooleanType.FromObject(Value), ContainedInVariant);
                        break;

                    case TypeCode.Char:
                        this.PutChar(RecordNumber, CharType.FromObject(Value), ContainedInVariant);
                        break;

                    case TypeCode.Byte:
                        this.PutByte(RecordNumber, ByteType.FromObject(Value), ContainedInVariant);
                        break;

                    case TypeCode.Int16:
                        this.PutShort(RecordNumber, ShortType.FromObject(Value), ContainedInVariant);
                        break;

                    case TypeCode.Int32:
                        this.PutInteger(RecordNumber, IntegerType.FromObject(Value), ContainedInVariant);
                        break;

                    case TypeCode.Int64:
                        this.PutLong(RecordNumber, LongType.FromObject(Value), ContainedInVariant);
                        break;

                    case TypeCode.Single:
                        this.PutSingle(RecordNumber, SingleType.FromObject(Value), ContainedInVariant);
                        break;

                    case TypeCode.Double:
                        this.PutDouble(RecordNumber, DoubleType.FromObject(Value), ContainedInVariant);
                        break;

                    case TypeCode.Decimal:
                        this.PutDecimal(RecordNumber, DecimalType.FromObject(Value), ContainedInVariant);
                        break;

                    case TypeCode.DateTime:
                        this.PutDate(RecordNumber, DateType.FromObject(Value), ContainedInVariant);
                        break;

                    case TypeCode.String:
                        this.PutVariantString(RecordNumber, Value.ToString());
                        break;

                    default:
                        if (type == typeof(Missing))
                        {
                            throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedIOType1", new string[1]
                            {
                                "Missing"
                            })), 5);
                        }
                        if (type.IsValueType && !ContainedInVariant)
                        {
                            this.PutRecord(RecordNumber, (ValueType)Value);
                            break;
                        }
                        if (ContainedInVariant && type.IsValueType)
                        {
                            throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_PutObjectOfValueType1", new string[1]
                            {
                                Utils.VBFriendlyName(type, Value)
                            })), 5);
                        }
                        throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedIOType1", new string[1]
                        {
                            Utils.VBFriendlyName(type, Value)
                        })), 5);
                    }
                }
            }
        }
コード例 #7
0
ファイル: PutHandler.cs プロジェクト: ysc0423/CommonCore
        public bool Callback(FieldInfo field_info, ref object vValue)
        {
            Type fieldType = field_info.FieldType;

            if (fieldType == null)
            {
                throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "Empty")), 5);
            }
            if (fieldType.IsArray)
            {
                int      FixedStringLength = -1;
                object[] customAttributes1 = field_info.GetCustomAttributes(typeof(VBFixedArrayAttribute), false);
                VBFixedArrayAttribute fixedArrayAttribute = customAttributes1 == null || customAttributes1.Length == 0 ? (VBFixedArrayAttribute)null : (VBFixedArrayAttribute)customAttributes1[0];
                Type elementType = fieldType.GetElementType();
                if (elementType == typeof(string))
                {
                    object[] customAttributes2 = field_info.GetCustomAttributes(typeof(VBFixedStringAttribute), false);
                    FixedStringLength = customAttributes2 == null || customAttributes2.Length == 0 ? -1 : ((VBFixedStringAttribute)customAttributes2[0]).Length;
                }
                if (fixedArrayAttribute == null)
                {
                    this.m_oFile.PutDynamicArray(0L, (Array)vValue, false, FixedStringLength);
                }
                else
                {
                    this.m_oFile.PutFixedArray(0L, (Array)vValue, elementType, FixedStringLength, fixedArrayAttribute.FirstBound, fixedArrayAttribute.SecondBound);
                }
            }
            else
            {
                switch (Type.GetTypeCode(fieldType))
                {
                case TypeCode.DBNull:
                    throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "DBNull")), 5);

                case TypeCode.Boolean:
                    this.m_oFile.PutBoolean(0L, BooleanType.FromObject(vValue), false);
                    break;

                case TypeCode.Char:
                    this.m_oFile.PutChar(0L, CharType.FromObject(vValue), false);
                    break;

                case TypeCode.Byte:
                    this.m_oFile.PutByte(0L, ByteType.FromObject(vValue), false);
                    break;

                case TypeCode.Int16:
                    this.m_oFile.PutShort(0L, ShortType.FromObject(vValue), false);
                    break;

                case TypeCode.Int32:
                    this.m_oFile.PutInteger(0L, IntegerType.FromObject(vValue), false);
                    break;

                case TypeCode.Int64:
                    this.m_oFile.PutLong(0L, LongType.FromObject(vValue), false);
                    break;

                case TypeCode.Single:
                    this.m_oFile.PutSingle(0L, SingleType.FromObject(vValue), false);
                    break;

                case TypeCode.Double:
                    this.m_oFile.PutDouble(0L, DoubleType.FromObject(vValue), false);
                    break;

                case TypeCode.Decimal:
                    this.m_oFile.PutDecimal(0L, DecimalType.FromObject(vValue), false);
                    break;

                case TypeCode.DateTime:
                    this.m_oFile.PutDate(0L, DateType.FromObject(vValue), false);
                    break;

                case TypeCode.String:
                    string   s = vValue == null ? (string)null : vValue.ToString();
                    object[] customAttributes = field_info.GetCustomAttributes(typeof(VBFixedStringAttribute), false);
                    if (customAttributes == null || customAttributes.Length == 0)
                    {
                        this.m_oFile.PutStringWithLength(0L, s);
                        break;
                    }
                    int lengthToWrite = ((VBFixedStringAttribute)customAttributes[0]).Length;
                    if (lengthToWrite == 0)
                    {
                        lengthToWrite = -1;
                    }
                    this.m_oFile.PutFixedLengthString(0L, s, lengthToWrite);
                    break;

                default:
                    if (fieldType == typeof(object))
                    {
                        this.m_oFile.PutObject(vValue, 0L, true);
                        break;
                    }
                    if (fieldType == typeof(Exception))
                    {
                        throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "Exception")), 5);
                    }
                    if (fieldType == typeof(Missing))
                    {
                        throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, "Missing")), 5);
                    }
                    throw ExceptionUtils.VbMakeException((Exception) new ArgumentException(Utils.GetResourceString("Argument_UnsupportedFieldType2", field_info.Name, fieldType.Name)), 5);
                }
            }
            bool flag = false;

            return(flag);
        }
コード例 #8
0
ファイル: VB6BinaryFile.cs プロジェクト: ysc0423/CommonCore
 internal override void Input(ref Decimal Value)
 {
     Value = DecimalType.FromObject(this.InputNum(VariantType.Decimal));
 }
コード例 #9
0
ファイル: DecimalType.cs プロジェクト: ysc0423/CommonCore
 /// <summary>Returns a <see langword="Decimal" /> value that corresponds to the specified object. </summary>
 /// <param name="Value">Required. Object to convert to a <see langword="Decimal" /> value.</param>
 /// <returns>The <see langword="Decimal" /> value that corresponds to <paramref name="Value" />.</returns>
 public static Decimal FromObject(object Value)
 {
     return(DecimalType.FromObject(Value, (NumberFormatInfo)null));
 }
コード例 #10
0
ファイル: DecimalType.cs プロジェクト: ysc0423/CommonCore
 /// <summary>Returns a <see langword="Decimal" /> value that corresponds to the specified string. </summary>
 /// <param name="Value">Required. String to convert to a <see langword="Decimal" /> value.</param>
 /// <returns>The <see langword="Decimal" /> value that corresponds to <paramref name="Value" />.</returns>
 public static Decimal FromString(string Value)
 {
     return(DecimalType.FromString(Value, (NumberFormatInfo)null));
 }