Esempio n. 1
0
 // Convert an object into a date value.
 public static DateTime FromObject(Object Value)
 {
                 #if !ECMA_COMPAT
     IConvertible ic = (Value as IConvertible);
     if (ic != null)
     {
         if (ic.GetTypeCode() != TypeCode.String)
         {
             return(ic.ToDateTime(null));
         }
         else
         {
             return(FromString(ic.ToString(null)));
         }
     }
                 #else
     if (Value is DateTime)
     {
         return((DateTime)Value);
     }
                 #endif
     throw new InvalidCastException
               (String.Format
                   (S._("VB_InvalidCast"),
                   (Value != null ? Value.GetType().ToString() : "null"),
                   "System.DateTime"));
 }
Esempio n. 2
0
        /// <summary>Gets the attribute of a specific enumeration item.
        /// </summary>
        /// <typeparam name="TAttribute">The type of the attribute class.</typeparam>
        /// <param name="value">The value, i.e. the item of the enumeration.</param>
        /// <returns>The first <typeparamref name="TAttribute"/> instance of <paramref name="value"/> or <c>null</c> if no such attribute is available.</returns>
        /// <remarks>Here, we use the <see cref="IConvertible"/> representation of a type-safe enumeration representation.</remarks>
        internal static TAttribute Create <TAttribute>(IConvertible value)
            where TAttribute : Attribute
        {
            Type type = value.GetType();

            MemberInfo[] memInfo = type.GetMember(value.ToString());
            if ((memInfo != null) && (memInfo.Length >= 1))
            {
                for (int j = 0; j < memInfo.Length; j++)
                {
                    object[] customAttributes = memInfo[j].GetCustomAttributes(typeof(TAttribute), false);
                    if ((customAttributes != null) && (customAttributes.Length > 0))
                    {
                        for (int k = 0; k < customAttributes.Length; k++)
                        {
                            if (customAttributes[k] is TAttribute)  // return the first attribute which corresponds to the given attribute type
                            {
                                return(customAttributes[k] as TAttribute);
                            }
                        }
                    }
                }
            }
            return(null);
        }
Esempio n. 3
0
 // Convert an object into a char array value.
 public static char[] FromObject(Object Value)
 {
     if (Value != null)
     {
         if (Value is char[])
         {
             return((char[])Value);
         }
                         #if !ECMA_COMPAT
         IConvertible ic = (Value as IConvertible);
         if (ic != null && ic.GetTypeCode() == TypeCode.String)
         {
             return(ic.ToString(null).ToCharArray());
         }
                         #else
         if (Value is String)
         {
             return(((String)Value).ToCharArray());
         }
                         #endif
         else
         {
             throw new InvalidCastException
                       (String.Format
                           (S._("VB_InvalidCast"),
                           Value.GetType(), "char[]"));
         }
     }
     else
     {
         return(new char [0]);
     }
 }
Esempio n. 4
0
        public void Convertible_ToStringInvariant_Equals_ToStringInvariantCulture()
        {
            IConvertible convertible = 1;
            var          formatted   = convertible.ToStringInvariant();

            Assert.AreEqual(convertible.ToString(CultureInfo.InvariantCulture), formatted);
        }
Esempio n. 5
0
        public static TR GetCustomEnumAttributeValue <T, TR>(this IConvertible @enum)
        {
            var attributeValue = default(TR);

            try
            {
                if (@enum != null)
                {
                    var fi = @enum.GetType().GetField(@enum.ToString(CultureInfo.InvariantCulture));
                    if (fi != null)
                    {
                        var attributes = fi.GetCustomAttributes(typeof(T), false) as T[];
                        if (attributes != null && attributes.Length > 0)
                        {
                            var attribute = attributes[0] as IAttribute <TR>;
                            if (attribute != null)
                            {
                                attributeValue = attribute.Value;
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                // ignored
            }
            return(attributeValue);
        }
Esempio n. 6
0
        public IComparable EvaluateComparable(IEvaluateContext context)
        {
            IConvertible result = Evaluate(context);

            if (result == null)
            {
                throw new LoadDataException("Could not evaluate " + _source);
            }
            if (result is EnumValue)
            {
                return((EnumValue)result);
            }
            if (result.GetTypeCode() == TypeCode.String)
            {
                return(result.ToString(CultureInfo.CurrentCulture));
            }
            else if (result.GetTypeCode() == TypeCode.UInt32)
            {
                uint value = result.ToUInt32(CultureInfo.CurrentCulture);
                return((int)value);
            }
            try
            {
                return(result.ToInt32(CultureInfo.CurrentCulture));
            }
            catch (OverflowException e)
            {
                throw new LoadDataException(e.Message);
            }
        }
Esempio n. 7
0
        public static bool IsNumeric(object Expression)
        {
            double       num;
            IConvertible convertible = Expression as IConvertible;

            if (convertible == null)
            {
                char[] chArray = Expression as char[];
                if (chArray == null)
                {
                    return(false);
                }
                Expression = new string(chArray);
            }

            TypeCode typeCode = convertible.GetTypeCode();

            if ((typeCode != TypeCode.String) && (typeCode != TypeCode.Char))
            {
                return(IsOldNumericTypeCode(typeCode));
            }

            string str = convertible.ToString(null);

            return(Double.TryParse(str, out num)); //simplified - NB, original code did more with HEX/OCTAL checking here.
        }
Esempio n. 8
0
 /// <summary>
 /// 数组列表转字符串
 /// </summary>
 /// <param name="list">需要合并的字符串数组</param>
 /// <param name="symbolSign">用于间隔内容的间隔符号</param>
 public static string ToString <T>(IList <T> list, IConvertible symbolSign)
 {
     try {
         if (CheckData.IsObjectNull(list) || CheckData.IsObjectNull(symbolSign))
         {
             return(string.Empty);
         }
         StringBuilder strs             = new StringBuilder();
         int           firstSign        = 0;
         bool          isHavefirstValue = false;
         for (int i = firstSign; i < list.Count; i++)
         {
             if (CheckData.IsObjectNull(list[i]) || CheckData.IsStringNull(list[i].ToString()))
             {
                 if (!isHavefirstValue)
                 {
                     firstSign = i + 1;
                 }
                 continue;
             }
             if (i > firstSign)
             {
                 strs.Append(symbolSign.ToString());
             }
             else
             {
                 isHavefirstValue = true;
             }
             strs.Append(list[i].ToString());
         }
         return(strs.ToString());
     } catch (Exception) {
         return(string.Empty);
     }
 }
Esempio n. 9
0
 public static float FromObject
     (Object Value, NumberFormatInfo NumberFormat)
 {
                 #if !ECMA_COMPAT
     if (Value != null)
     {
         IConvertible ic = (Value as IConvertible);
         if (ic != null)
         {
             if (ic.GetTypeCode() != TypeCode.String)
             {
                 return(ic.ToSingle(NumberFormat));
             }
             else
             {
                 return(FromString(ic.ToString(null), NumberFormat));
             }
         }
         else
         {
             throw new InvalidCastException
                       (String.Format
                           (S._("VB_InvalidCast"),
                           Value.GetType(), "System.Single"));
         }
     }
     else
     {
         return(0.0f);
     }
                 #else
     return((float)(DoubleType.FromObject(Value, NumberFormat)));
                 #endif
 }
Esempio n. 10
0
        public GameObject CreateLargeInputFieldWidget(
            GameObject parent = null,
            IConvertible text = null,
            UnityEngine.Events.UnityAction <string> onEndEdit = null,
            ContainerConfig configOverride = ContainerConfig.Submissive,
            int index = -1,
            int slots = -1)
        {
            GameObject inputFieldWidget = GameObject.Instantiate(inputFieldPrefab);

            if (text == null)
            {
                text = "";
            }

            TMPro.TMP_InputField inputField = inputFieldWidget.GetComponent <TMPro.TMP_InputField>();
            inputField.text = text.ToString();

            //Attach to parent and load up appropriate configurations
            CoupleToParent(
                widget: inputFieldWidget,
                parent: parent,
                index: index,
                slots: slots,
                config: configOverride);

            if (onEndEdit != null)
            {
                inputField.onEndEdit.AddListener(onEndEdit);
            }

            return(inputFieldWidget);
        }
        public static string ToStringWithCulture(object objectToConvert)
        {
            if (objectToConvert == null)
            {
                throw new ArgumentNullException(nameof(objectToConvert));
            }

            IConvertible conv = objectToConvert as IConvertible;

            if (conv != null)
            {
                return(conv.ToString(formatProvider));
            }

            var str = objectToConvert as string;

            if (str != null)
            {
                return(str);
            }

            //TODO: implement a cache of types and DynamicMethods
            MethodInfo mi = objectToConvert.GetType().GetMethod("ToString", new Type[] { typeof(IFormatProvider) });

            if (mi != null)
            {
                return((string)mi.Invoke(objectToConvert, formatProviderAsParameterArray));
            }
            return(objectToConvert.ToString());
        }
Esempio n. 12
0
        public static R GetAttributeValue <T, R>(IConvertible @enum)
        {
            R attributeValue = default(R);

            if (@enum != null)
            {
                FieldInfo fi = @enum.GetType().GetField(@enum.ToString());

                if (fi != null)
                {
                    T[] attributes = fi.GetCustomAttributes(typeof(T), false) as T[];

                    if (attributes != null && attributes.Length > 0)
                    {
                        IAttribute <R> attribute = attributes[0] as IAttribute <R>;

                        if (attribute != null)
                        {
                            attributeValue = attribute.Value;
                        }
                    }
                }
            }

            return(attributeValue);
        }
Esempio n. 13
0
 private static Object DoOp(Object v1, Object v2, IConvertible ic1, IConvertible ic2, JSToken operatorTok)
 {
     if (operatorTok == JSToken.Minus)
     {
         IConvertible ic1a = ic1;
         Object       p1   = Convert.ToPrimitive(v1, PreferredType.Either, ref ic1a);
         TypeCode     t1   = Convert.GetTypeCode(p1, ic1a);
         if (t1 == TypeCode.Char)
         {
             IConvertible ic2a = ic2;
             Object       p2   = Convert.ToPrimitive(v2, PreferredType.Either, ref ic2a);
             TypeCode     t2   = Convert.GetTypeCode(p2, ic2a);
             if (t2 == TypeCode.String)
             {
                 String str2 = ic2a.ToString(null);
                 if (str2.Length == 1)
                 {
                     t2   = TypeCode.Char;
                     p2   = str2[0];
                     ic2a = Convert.GetIConvertible(p2);
                 }
             }
             Object result = NumericBinary.DoOp(Convert.ToNumber(p1, ic1a), Convert.ToNumber(p2, ic2a), operatorTok);
             if (t2 != TypeCode.Char)
             {
                 result = Convert.Coerce2(result, TypeCode.Char, false);
             }
             return(result);
         }
     }
     return(NumericBinary.DoOp(Convert.ToNumber(v1, ic1), Convert.ToNumber(v2, ic2), operatorTok));
 }
 private static object DoOp(object v1, object v2, IConvertible ic1, IConvertible ic2, JSToken operatorTok)
 {
     if (operatorTok == JSToken.Minus)
     {
         IConvertible ic = ic1;
         object       ob = Microsoft.JScript.Convert.ToPrimitive(v1, PreferredType.Either, ref ic);
         if (Microsoft.JScript.Convert.GetTypeCode(ob, ic) == TypeCode.Char)
         {
             IConvertible iConvertible = ic2;
             object       obj3         = Microsoft.JScript.Convert.ToPrimitive(v2, PreferredType.Either, ref iConvertible);
             TypeCode     typeCode     = Microsoft.JScript.Convert.GetTypeCode(obj3, iConvertible);
             if (typeCode == TypeCode.String)
             {
                 string str = iConvertible.ToString(null);
                 if (str.Length == 1)
                 {
                     typeCode     = TypeCode.Char;
                     obj3         = str[0];
                     iConvertible = Microsoft.JScript.Convert.GetIConvertible(obj3);
                 }
             }
             object obj4 = DoOp(Microsoft.JScript.Convert.ToNumber(ob, ic), Microsoft.JScript.Convert.ToNumber(obj3, iConvertible), operatorTok);
             if (typeCode != TypeCode.Char)
             {
                 obj4 = Microsoft.JScript.Convert.Coerce2(obj4, TypeCode.Char, false);
             }
             return(obj4);
         }
     }
     return(DoOp(Microsoft.JScript.Convert.ToNumber(v1, ic1), Microsoft.JScript.Convert.ToNumber(v2, ic2), operatorTok));
 }
Esempio n. 15
0
 private void SerializeSimpleTypeCodeValue(IConvertible value, TypeCode objTypeCode, StringBuilder destination, JsonSerializeOptions options, bool forceToString = false)
 {
     if (value == null)
     {
         destination.Append(forceToString ? "\"\"" : "null");
     }
     else if (objTypeCode == TypeCode.String || objTypeCode == TypeCode.Char)
     {
         destination.Append('"');
         AppendStringEscape(destination, value.ToString(), options);
         destination.Append('"');
     }
     else
     {
         var hasFormat = !StringHelpers.IsNullOrWhiteSpace(options.Format);
         if ((options.FormatProvider != null || hasFormat) && (value is IFormattable formattable))
         {
             bool includeQuotes = forceToString || objTypeCode == TypeCode.Object || !SkipQuotes(value, objTypeCode);
             SerializeWithFormatProvider(formattable, includeQuotes, destination, options, hasFormat);
         }
         else
         {
             SerializeSimpleTypeCodeValueNoEscape(value, objTypeCode, destination, options, forceToString);
         }
     }
 }
Esempio n. 16
0
        public static string GetEnumDescription(IConvertible value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());

            DescriptionAttribute[] attributes =
                (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);

            if (attributes != null && attributes.Length > 0)
            {
                return(attributes[0].Description);
            }
            else
            {
                return(value.ToString());
            }
        }
 /// <summary>
 /// Writes an IConvertible value
 /// </summary>
 /// <param name="value"></param>
 /// <param name="writer"></param>
 /// <param name="options"></param>
 protected void WriteConvertibleValue(IConvertible value, Utf8JsonWriter writer, JsonSerializerOptions options)
 {
     if (Util.IsDecimal(value))
     {
         if (Util.IsFloat(value))
         {
             writer.WriteNumberValue((float)value);
         }
         else
         {
             writer.WriteNumberValue((double)value);
         }
     }
     else if (Util.IsBoolean(value))
     {
         writer.WriteBooleanValue((bool)value);
     }
     else if (Util.IsNumeric(value))
     {
         writer.WriteNumberValue((int)value);
     }
     else
     {
         writer.WriteStringValue(value.ToString());
     }
 }
Esempio n. 18
0
		public RepositoryResponse<bool> Validate<T>(IConvertible id, string specificulture, JObject jItem, MixCmsContext _context = null, IDbContextTransaction _transaction = null)
		where T : class
		{
			V_0 = new ApiModuleDataValueViewModel.u003cu003ec__DisplayClass40_0<T>();
			V_0.specificulture = specificulture;
			V_1 = Newtonsoft.Json.Linq.Extensions.Value<string>(jItem.get_Item(this.get_Name()).get_Item("value"));
			V_0.jVal = new JProperty(this.get_Name(), jItem.get_Item(this.get_Name()));
			stackVariable18 = new RepositoryResponse<bool>();
			stackVariable18.set_IsSucceed(true);
			V_2 = stackVariable18;
			if (this.get_IsUnique())
			{
				stackVariable35 = V_0;
				if (id != null)
				{
					stackVariable38 = id.ToString();
				}
				else
				{
					stackVariable38 = null;
				}
				stackVariable35.strId = stackVariable38;
				stackVariable40 = _context.get_MixModuleData();
				V_3 = Expression.Parameter(Type.GetTypeFromHandle(// 
				// Current member / type: Mix.Domain.Core.ViewModels.RepositoryResponse`1<System.Boolean> Mix.Cms.Lib.ViewModels.ApiModuleDataValueViewModel::Validate(System.IConvertible,System.String,Newtonsoft.Json.Linq.JObject,Mix.Cms.Lib.Models.Cms.MixCmsContext,Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction)
				// Exception in: Mix.Domain.Core.ViewModels.RepositoryResponse<System.Boolean> Validate(System.IConvertible,System.String,Newtonsoft.Json.Linq.JObject,Mix.Cms.Lib.Models.Cms.MixCmsContext,Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction)
				// Specified method is not supported.
				// 
				// mailto: [email protected]

	}
}
Esempio n. 19
0
 // Convert an object into a short value.
 public static short FromObject(Object Value)
 {
                 #if !ECMA_COMPAT
     if (Value != null)
     {
         IConvertible ic = (Value as IConvertible);
         if (ic != null)
         {
             if (ic.GetTypeCode() != TypeCode.String)
             {
                 return(ic.ToInt16(null));
             }
             else
             {
                 return(FromString(ic.ToString(null)));
             }
         }
         else
         {
             throw new InvalidCastException
                       (String.Format
                           (S._("VB_InvalidCast"),
                           Value.GetType(), "System.Int16"));
         }
     }
     else
     {
         return(0);
     }
                 #else
     return(checked ((short)(LongType.FromObject(Value))));
                 #endif
 }
Esempio n. 20
0
            void SaveBinary(RegistryKey regKey, object instance)
            {
                var value = PropertyInfo.GetValue(instance, null);

                byte[] data;
                if (IsEnum)
                {
                    data = new byte[8];
                    BitConverter.GetBytes(Convert.ToInt64(value)).CopyTo(data, 0);
                }
                else if (IsIConvertible)
                {
                    IConvertible convertible = value as IConvertible;
                    data = Encoding.UTF8.GetBytes(convertible?.ToString(CultureInfo.InvariantCulture));
                }
                else if (value is byte[])
                {
                    data = (byte[])value;
                }
                else
                {
                    data = Encoding.UTF8.GetBytes(value?.ToString() ?? string.Empty);
                }
                if (Obfuscate)
                {
                    data = data.Obfuscate();
                }
                regKey.SetValue(Name, data, ValueKind);
            }
Esempio n. 21
0
        public static bool IsNumeric(object item)
        {
            IConvertible convertible = item as IConvertible;

            if ((object)convertible != null)
            {
                switch (convertible.GetTypeCode())
                {
                case TypeCode.Boolean:
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                case TypeCode.UInt64:
                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                    return(true);

                case TypeCode.Char:
                case TypeCode.String:
                    double result;
                    return(double.TryParse(convertible.ToString(null), out result));
                }
            }

            return(false);
        }
        public void ValuesAreConvertible()
        {
            RedisValue val = 123;
            object     o   = val;

            byte[] blob = (byte[])Convert.ChangeType(o, typeof(byte[]));

            Assert.Equal(3, blob.Length);
            Assert.Equal((byte)'1', blob[0]);
            Assert.Equal((byte)'2', blob[1]);
            Assert.Equal((byte)'3', blob[2]);

            Assert.Equal((double)123, Convert.ToDouble(o));

            IConvertible c = (IConvertible)o;

            Assert.Equal((short)123, c.ToInt16(CultureInfo.InvariantCulture));
            Assert.Equal((int)123, c.ToInt32(CultureInfo.InvariantCulture));
            Assert.Equal((long)123, c.ToInt64(CultureInfo.InvariantCulture));
            Assert.Equal((float)123, c.ToSingle(CultureInfo.InvariantCulture));
            Assert.Equal("123", c.ToString(CultureInfo.InvariantCulture));
            Assert.Equal((double)123, c.ToDouble(CultureInfo.InvariantCulture));
            Assert.Equal((decimal)123, c.ToDecimal(CultureInfo.InvariantCulture));
            Assert.Equal((ushort)123, c.ToUInt16(CultureInfo.InvariantCulture));
            Assert.Equal((uint)123, c.ToUInt32(CultureInfo.InvariantCulture));
            Assert.Equal((ulong)123, c.ToUInt64(CultureInfo.InvariantCulture));

            blob = (byte[])c.ToType(typeof(byte[]), CultureInfo.InvariantCulture);
            Assert.Equal(3, blob.Length);
            Assert.Equal((byte)'1', blob[0]);
            Assert.Equal((byte)'2', blob[1]);
            Assert.Equal((byte)'3', blob[2]);
        }
Esempio n. 23
0
 public static string ToInvariantString(this object obj)
 {
     if (obj != null)
     {
         if (!(obj is DateTime))
         {
             if (!(obj is DateTimeOffset))
             {
                 IConvertible c = obj as IConvertible;
                 if (c == null)
                 {
                     IFormattable f = obj as IFormattable;
                     if (f == null)
                     {
                         return(obj.ToString());
                     }
                     return(f.ToString(null, CultureInfo.InvariantCulture));
                 }
                 return(c.ToString(CultureInfo.InvariantCulture));
             }
             return(((DateTimeOffset)obj).ToString("o", CultureInfo.InvariantCulture));
         }
         return(((DateTime)obj).ToString("o", CultureInfo.InvariantCulture));
     }
     return(null);
 }
Esempio n. 24
0
        public override void Write(Utf8JsonWriter writer, VariableValue value, JsonSerializerOptions options)
        {
            if (value.IsConvertible())
            {
                IConvertible val = value.GetValueConvertible();

                if (val is String)
                {
                    writer.WriteStringValue(val.ToString());
                }
                else if (Util.IsBoolean(val))
                {
                    writer.WriteBooleanValue((bool)val);
                }
                else if (Util.IsNumeric(val))
                {
                    if (Util.IsFloat(val))
                    {
                        writer.WriteNumberValue((float)val);
                    }
                    else if (Util.IsDecimal(val))
                    {
                        writer.WriteNumberValue((decimal)val);
                    }
                    else
                    {
                        writer.WriteNumberValue((int)val);
                    }
                }
            }
            else if (value.IsArray())
            {
                writer.WriteStartArray();

                foreach (VariableValue v in value.GetValueArray())
                {
                    JsonSerializer.Serialize <VariableValue>(writer, v, options);
                }

                writer.WriteEndArray();
            }
            else if (value.IsDictionary())
            {
                writer.WriteStartObject();

                foreach (KeyValuePair <String, VariableValue> v in value.GetValueDictionary())
                {
                    writer.WritePropertyName(v.Key);

                    JsonSerializer.Serialize <VariableValue>(writer, v.Value, options);
                }

                writer.WriteEndObject();
            }
            else
            {
                throw new MerchantAPIException(String.Format("Invalid value data type {0}", value.ValueType));
            }
        }
        /// <summary>
        /// Converts the value of this instance to an equivalent 32-bit signed integer using the specified style and culture-specific
        /// format.
        /// </summary>
        /// <param name="convertible">The <see cref="IConvertible"/> instance to convert.</param>
        /// <param name="formatProvider">
        /// An <see cref="IFormatProvider"/> interface implementation that supplies culture-specific formatting information.
        /// </param>
        /// <param name="style">
        /// A bitwise combination of enumeration values that indicates the style elements that can be present.
        /// </param>
        /// <returns>A 32-bit signed integer equivalent to the number specified in <c>convertible</c>.</returns>
        public static int ToInt32(this IConvertible convertible, IFormatProvider?formatProvider, NumberStyles style)
        {
            Require.NotNull(convertible, nameof(convertible));

            string stringEquivalent = convertible.ToString(formatProvider);

            return(int.Parse(stringEquivalent, style, formatProvider));
        }
 public static string ToInvariantString(this IConvertible @this)
 {
     if (@this is null)
     {
         throw new ArgumentNullException(nameof(@this));
     }
     return(@this.ToString(CultureInfo.InvariantCulture));
 }
Esempio n. 27
0
        public static IEnumerable <T> GetAttributes <T>(this IConvertible value)
            where T : Attribute
        {
            var fieldInfo  = value.GetType().GetField(value.ToString());
            var attributes = (IEnumerable <T>)fieldInfo.GetCustomAttributes(typeof(T), false);

            return(attributes);
        }
        static string ToInvariantCultureString(object value)
        {
            IConvertible convertible = value as IConvertible;

            return((null != convertible)
                                ? convertible.ToString(System.Globalization.CultureInfo.InvariantCulture)
                                : value.ToString());
        }
Esempio n. 29
0
 void WriteKeyValuePair(string name, IConvertible value)
 {
     WriteIndentation();
     WriteText(name);
     writer.Write('\t');
     WriteText(value.ToString(null));
     WriteLine();
 }
Esempio n. 30
0
 public override string AddNumber(IConvertible number, IList <DbParameter> parameters)
 {
     if (number == null)
     {
         throw new ArgumentNullException("number");
     }
     return(number.ToString());
 }
Esempio n. 31
0
 public override string AddNumber(IConvertible number, IList<DbParameter> parameters)
 {
     if (number == null)
     {
         throw new ArgumentNullException("number");
     }
     return number.ToString();
 }
Esempio n. 32
0
        protected override IConvertible DoBinOp(IConvertible left, IConvertible right)
        {
            TypeCode typeCode = GetValueType(left, right);

            switch (typeCode)
            {
                case TypeCode.SByte:
                    return (Convert.ToSByte(left) + Convert.ToSByte(right));

                case TypeCode.Byte:
                    return (Convert.ToByte(left) + Convert.ToByte(right));

                case TypeCode.Int16:
                    return (Convert.ToInt16(left) + Convert.ToInt16(right));

                case TypeCode.UInt16:
                    return (Convert.ToUInt16(left) + Convert.ToUInt16(right));

                case TypeCode.Int32:
                    return (Convert.ToInt32(left) + Convert.ToInt32(right));

                case TypeCode.UInt32:
                    return (Convert.ToUInt32(left) + Convert.ToUInt32(right));

                case TypeCode.Int64:
                    return (Convert.ToInt64(left) + Convert.ToInt64(right));

                case TypeCode.UInt64:
                    return (Convert.ToUInt64(left) + Convert.ToUInt64(right));

                case TypeCode.Double:
                    return (Convert.ToDouble(left) + Convert.ToDouble(right));

                case TypeCode.Decimal:
                    return (Convert.ToDecimal(left) + Convert.ToDecimal(right));

            }

            return left.ToString() + right.ToString();
        }
Esempio n. 33
0
      private static double JScriptCompare2(Object v1, Object v2, IConvertible ic1, IConvertible ic2, TypeCode t1, TypeCode t2){
        if (t1 == TypeCode.Object){
          v1 = Convert.ToPrimitive(v1, PreferredType.Number, ref ic1);
          t1 = Convert.GetTypeCode(v1, ic1);
        }
        if (t2 == TypeCode.Object){
          v2 = Convert.ToPrimitive(v2, PreferredType.Number, ref ic2);
          t2 = Convert.GetTypeCode(v2, ic2);
        }
        switch (t1){
          case TypeCode.Char:
            if (t2 == TypeCode.String) return String.CompareOrdinal(Convert.ToString(v1, ic1), ic2.ToString(null));
            goto case TypeCode.UInt16;

          case TypeCode.SByte:
          case TypeCode.Byte:
          case TypeCode.Int16:
          case TypeCode.UInt16:
          case TypeCode.Int32:
          case TypeCode.UInt32:
          case TypeCode.Int64:
            long l = ic1.ToInt64(null);
            switch (t2){
              case TypeCode.SByte:
              case TypeCode.Byte:
              case TypeCode.Int16:
              case TypeCode.UInt16:
              case TypeCode.Int32:
              case TypeCode.UInt32:
              case TypeCode.Int64:
                return l - ic2.ToInt64(null);
              case TypeCode.UInt64:
                if (l < 0) return -1;
                ulong ul2 = ic2.ToUInt64(null);
                if (((ulong)l) < ul2) return -1;
                if (((ulong)l) == ul2) return 0;
                return 1;
              case TypeCode.Single:
              case TypeCode.Double:
                return ((double)l) - ic2.ToDouble(null);
              case TypeCode.Decimal:
                return (double)(new Decimal(l) - ic2.ToDecimal(null));
              default:
                Object bd2 = Convert.ToNumber(v2, ic2);
                return JScriptCompare2(v1, bd2, ic1, Convert.GetIConvertible(bd2), t1, TypeCode.Double);
            }

          case TypeCode.UInt64:
            ulong ul = ic1.ToUInt64(null);
            switch (t2){
              case TypeCode.SByte:
              case TypeCode.Byte:
              case TypeCode.Int16:
              case TypeCode.UInt16:
              case TypeCode.Int32:
              case TypeCode.UInt32:
              case TypeCode.Int64:
                long l2 = ic2.ToInt64(null);
                if (l2 < 0) return 1;
                if (ul == (ulong)l2) return 0;
                return -1;
              case TypeCode.UInt64:
                ulong ul2 = ic2.ToUInt64(null);
                if (ul < ul2) return -1;
                if (ul == ul2) return 0;
                return 1;
              case TypeCode.Single:
              case TypeCode.Double:
                return ((double)ul) - ic2.ToDouble(null);
              case TypeCode.Decimal:
                return (double)(new Decimal(ul) - ic2.ToDecimal(null));
              default:
                Object bd2 = Convert.ToNumber(v2, ic2);
                return JScriptCompare2(v1, bd2, ic1, Convert.GetIConvertible(bd2), t1, TypeCode.Double);
            }

          case TypeCode.Decimal:
            Decimal dec1 = ic1.ToDecimal(null);
            switch (t2){
              case TypeCode.SByte:
              case TypeCode.Byte:
              case TypeCode.Int16:
              case TypeCode.UInt16:
              case TypeCode.Int32:
              case TypeCode.UInt32:
              case TypeCode.Int64:
                return (double)(dec1 - new Decimal(ic2.ToInt64(null)));
              case TypeCode.UInt64:
                return (double)(dec1 - new Decimal(ic2.ToUInt64(null)));
              case TypeCode.Single:
              case TypeCode.Double:
                return (double)(dec1 - new Decimal(ic2.ToDouble(null)));
              case TypeCode.Decimal:
                return (double)(dec1 - ic2.ToDecimal(null));
              default:
                return (double)(dec1 - new Decimal(Convert.ToNumber(v2, ic2)));
            }

          case TypeCode.String:
            switch (t2){
              case TypeCode.String: return String.CompareOrdinal(ic1.ToString(null), ic2.ToString(null));
              case TypeCode.Char : return String.CompareOrdinal(ic1.ToString(null), Convert.ToString(v2, ic2));
            }
            goto default;

          default:
            double d1 = Convert.ToNumber(v1, ic1);
            double d2 = Convert.ToNumber(v2, ic2);
            if (d1 == d2) return 0; //d1 and d2 could be infinities
            return d1 - d2;
        }
      }
Esempio n. 34
0
        internal static Object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
        {
            Contract.Requires(value != null, "[Convert.DefaultToType]value!=null");
            if (targetType == null)
            {
                throw new ArgumentNullException("targetType");
            }
            Contract.EndContractBlock();

            if (value.GetType() == targetType)
                return value;

            if (targetType == CommonRuntimeTypes.Boolean)
                return value.ToBoolean(provider);
            if (targetType == CommonRuntimeTypes.Char)
                return value.ToChar(provider);
            if (targetType == CommonRuntimeTypes.SByte)
                return value.ToSByte(provider);
            if (targetType == CommonRuntimeTypes.Byte)
                return value.ToByte(provider);
            if (targetType == CommonRuntimeTypes.Int16)
                return value.ToInt16(provider);
            if (targetType == CommonRuntimeTypes.UInt16)
                return value.ToUInt16(provider);
            if (targetType == CommonRuntimeTypes.Int32)
                return value.ToInt32(provider);
            if (targetType == CommonRuntimeTypes.UInt32)
                return value.ToUInt32(provider);
            if (targetType == CommonRuntimeTypes.Int64)
                return value.ToInt64(provider);
            if (targetType == CommonRuntimeTypes.UInt64)
                return value.ToUInt64(provider);
            if (targetType == CommonRuntimeTypes.Single)
                return value.ToSingle(provider);
            if (targetType == CommonRuntimeTypes.Double)
                return value.ToDouble(provider);
            if (targetType == CommonRuntimeTypes.Decimal)
                return value.ToDecimal(provider);
            if (targetType == CommonRuntimeTypes.DateTime)
                return value.ToDateTime(provider);
            if (targetType == CommonRuntimeTypes.String)
                return value.ToString(provider);
            if (targetType == CommonRuntimeTypes.Object)
                return (Object)value;
            if (targetType == CommonRuntimeTypes.Enum)
                return (Enum)value;

            throw new InvalidCastException(SR.Format(SR.InvalidCast_FromTo, value.GetType().ToString(), targetType.Name));
        }
Esempio n. 35
0
 public static void WriteIconvertible(IConvertible input)
 {
     Console.WriteLine(input.ToString(null));
 }
 private static void Guarda(Campo elCampo, IConvertible elNúmero, string elTexto, StreamWriter elEscritor)
 {
     elEscritor.WriteLine(
     elCampo.Identificador + elNúmero.ToString(CultureInfo.InvariantCulture)
     + "=" + elTexto);
 }
Esempio n. 37
0
 /// <summary>
 /// Checks the result code of the tests execution and performs the
 /// corresponding action.
 /// </summary>
 /// <param name="resultCode">The result code returned by the Run method of the
 /// TestRunnerHelper class.</param>
 private void SetResultProperty(IConvertible resultCode)
 {
     if (!String.IsNullOrEmpty(ResultProperty))
     {
         Properties[ResultProperty] = resultCode.ToString(CultureInfo.InvariantCulture);
     }
 }
Esempio n. 38
0
        private void EmitConstant(IConvertible ic)
        {
            this.StackSize++;
              TypeCode tc = ic.GetTypeCode();
              switch (tc) {
            case TypeCode.Boolean:
            case TypeCode.SByte:
            case TypeCode.Byte:
            case TypeCode.Char:
            case TypeCode.Int16:
            case TypeCode.UInt16:
            case TypeCode.Int32:
            case TypeCode.UInt32:
            case TypeCode.Int64:
              long n = ic.ToInt64(null);
              switch (n) {
            case -1: this.generator.Emit(OperationCode.Ldc_I4_M1); break;
            case 0: this.generator.Emit(OperationCode.Ldc_I4_0); break;
            case 1: this.generator.Emit(OperationCode.Ldc_I4_1); break;
            case 2: this.generator.Emit(OperationCode.Ldc_I4_2); break;
            case 3: this.generator.Emit(OperationCode.Ldc_I4_3); break;
            case 4: this.generator.Emit(OperationCode.Ldc_I4_4); break;
            case 5: this.generator.Emit(OperationCode.Ldc_I4_5); break;
            case 6: this.generator.Emit(OperationCode.Ldc_I4_6); break;
            case 7: this.generator.Emit(OperationCode.Ldc_I4_7); break;
            case 8: this.generator.Emit(OperationCode.Ldc_I4_8); break;
            default:
              if (sbyte.MinValue <= n && n <= sbyte.MaxValue) {
                this.generator.Emit(OperationCode.Ldc_I4_S, (sbyte)n);
              } else if (int.MinValue <= n && n <= int.MaxValue ||
                n <= uint.MaxValue && (tc == TypeCode.Char || tc == TypeCode.UInt16 || tc == TypeCode.UInt32)) {
                if (n == uint.MaxValue)
                  this.generator.Emit(OperationCode.Ldc_I4_M1);
                else
                  this.generator.Emit(OperationCode.Ldc_I4, (int)n);
              } else {
                this.generator.Emit(OperationCode.Ldc_I8, n);
                tc = TypeCode.Empty; //Suppress conversion to long
              }
              break;
              }
              if (tc == TypeCode.Int64)
            this.generator.Emit(OperationCode.Conv_I8);
              return;

            case TypeCode.UInt64:
              this.generator.Emit(OperationCode.Ldc_I8, (long)ic.ToUInt64(null));
              return;

            case TypeCode.Single:
              this.generator.Emit(OperationCode.Ldc_R4, ic.ToSingle(null));
              return;

            case TypeCode.Double:
              this.generator.Emit(OperationCode.Ldc_R8, ic.ToDouble(null));
              return;

            case TypeCode.String:
              this.generator.Emit(OperationCode.Ldstr, ic.ToString(null));
              return;

            case TypeCode.Decimal:
              var bits = Decimal.GetBits(ic.ToDecimal(null));
              this.generator.Emit(OperationCode.Ldc_I4, bits[0]);
              this.generator.Emit(OperationCode.Ldc_I4, bits[1]); this.StackSize++;
              this.generator.Emit(OperationCode.Ldc_I4, bits[2]); this.StackSize++;
              if (bits[3] >= 0)
            this.generator.Emit(OperationCode.Ldc_I4_0);
              else
            this.generator.Emit(OperationCode.Ldc_I4_1);
              this.StackSize++;
              int scale = (bits[3]&0x7FFFFF)>>16;
              if (scale > 28) scale = 28;
              this.generator.Emit(OperationCode.Ldc_I4_S, scale); this.StackSize++;
              this.generator.Emit(OperationCode.Newobj, this.DecimalConstructor);
              this.StackSize -= 4;
              return;
              }
        }
Esempio n. 39
0
        internal static Object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) {
            Contract.Requires(value != null, "[Convert.DefaultToType]value!=null");
            if (targetType==null) {
                throw new ArgumentNullException("targetType");
            }
            Contract.EndContractBlock();

            RuntimeType rtTargetType = targetType as RuntimeType;

            if (rtTargetType != null)
            {
                if (value.GetType() == targetType)
                {
                    return value;
                }

                if (rtTargetType == ConvertTypes[(int)TypeCode.Boolean])
                    return value.ToBoolean(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.Char])
                    return value.ToChar(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.SByte])
                    return value.ToSByte(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.Byte])
                    return value.ToByte(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.Int16])
                    return value.ToInt16(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.UInt16])
                    return value.ToUInt16(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.Int32])
                    return value.ToInt32(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.UInt32])
                    return value.ToUInt32(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.Int64])
                    return value.ToInt64(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.UInt64])
                    return value.ToUInt64(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.Single])
                    return value.ToSingle(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.Double])
                    return value.ToDouble(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.Decimal])
                    return value.ToDecimal(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.DateTime])
                    return value.ToDateTime(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.String])
                    return value.ToString(provider);
                if (rtTargetType == ConvertTypes[(int)TypeCode.Object])
                    return (Object)value;
                //  Need to special case Enum because typecode will be underlying type, e.g. Int32
                if (rtTargetType == EnumType)
                    return (Enum)value;
                if (rtTargetType == ConvertTypes[(int)TypeCode.DBNull])
                    throw new InvalidCastException(Environment.GetResourceString("InvalidCast_DBNull"));
                if (rtTargetType == ConvertTypes[(int)TypeCode.Empty])
                    throw new InvalidCastException(Environment.GetResourceString("InvalidCast_Empty"));
            }

            throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", value.GetType().FullName, targetType.FullName));
        }
        internal static bool JScriptStrictEquals(object v1, object v2, IConvertible ic1, IConvertible ic2, TypeCode t1, TypeCode t2, bool checkForDebuggerObjects)
        {
            long num7;
            switch (t1)
            {
                case TypeCode.Empty:
                    return (t2 == TypeCode.Empty);

                case TypeCode.Object:
                    if (v1 != v2)
                    {
                        if ((v1 is Microsoft.JScript.Missing) || (v1 is System.Reflection.Missing))
                        {
                            v1 = null;
                        }
                        if (v1 == v2)
                        {
                            return true;
                        }
                        if ((v2 is Microsoft.JScript.Missing) || (v2 is System.Reflection.Missing))
                        {
                            v2 = null;
                        }
                        if (checkForDebuggerObjects)
                        {
                            IDebuggerObject obj2 = v1 as IDebuggerObject;
                            if (obj2 != null)
                            {
                                IDebuggerObject o = v2 as IDebuggerObject;
                                if (o != null)
                                {
                                    return obj2.IsEqual(o);
                                }
                            }
                        }
                        return (v1 == v2);
                    }
                    return true;

                case TypeCode.DBNull:
                    return (t2 == TypeCode.DBNull);

                case TypeCode.Boolean:
                    if (t2 != TypeCode.Boolean)
                    {
                        return false;
                    }
                    return (ic1.ToBoolean(null) == ic2.ToBoolean(null));

                case TypeCode.Char:
                {
                    char ch = ic1.ToChar(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (ch == ic2.ToChar(null));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (ch == ic2.ToInt64(null));

                        case TypeCode.UInt64:
                            return (ch == ic2.ToUInt64(null));

                        case TypeCode.Single:
                        case TypeCode.Double:
                            return (((double) ch) == ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (ch == ic2.ToDecimal(null));

                        case TypeCode.String:
                        {
                            string str = ic2.ToString(null);
                            return ((str.Length == 1) && (ch == str[0]));
                        }
                    }
                    break;
                }
                case TypeCode.SByte:
                {
                    sbyte num = ic1.ToSByte(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (num == ic2.ToChar(null));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (num == ic2.ToInt64(null));

                        case TypeCode.UInt64:
                            return ((num >= 0) && (num == ic2.ToUInt64(null)));

                        case TypeCode.Single:
                            return (num == ic2.ToSingle(null));

                        case TypeCode.Double:
                            return (num == ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (num == ic2.ToDecimal(null));
                    }
                    return false;
                }
                case TypeCode.Byte:
                {
                    byte num2 = ic1.ToByte(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (num2 == ic2.ToChar(null));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (num2 == ic2.ToInt64(null));

                        case TypeCode.UInt64:
                            return (num2 == ic2.ToUInt64(null));

                        case TypeCode.Single:
                            return (num2 == ic2.ToSingle(null));

                        case TypeCode.Double:
                            return (num2 == ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (num2 == ic2.ToDecimal(null));
                    }
                    return false;
                }
                case TypeCode.Int16:
                {
                    short num3 = ic1.ToInt16(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (num3 == ic2.ToChar(null));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (num3 == ic2.ToInt64(null));

                        case TypeCode.UInt64:
                            return ((num3 >= 0) && (num3 == ic2.ToUInt64(null)));

                        case TypeCode.Single:
                            return (num3 == ic2.ToSingle(null));

                        case TypeCode.Double:
                            return (num3 == ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (num3 == ic2.ToDecimal(null));
                    }
                    return false;
                }
                case TypeCode.UInt16:
                {
                    ushort num4 = ic1.ToUInt16(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (num4 == ic2.ToChar(null));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (num4 == ic2.ToInt64(null));

                        case TypeCode.UInt64:
                            return (num4 == ic2.ToUInt64(null));

                        case TypeCode.Single:
                            return (num4 == ic2.ToSingle(null));

                        case TypeCode.Double:
                            return (num4 == ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (num4 == ic2.ToDecimal(null));
                    }
                    return false;
                }
                case TypeCode.Int32:
                {
                    int num5 = ic1.ToInt32(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (num5 == ic2.ToChar(null));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (num5 == ic2.ToInt64(null));

                        case TypeCode.UInt64:
                            return ((num5 >= 0) && (num5 == ic2.ToUInt64(null)));

                        case TypeCode.Single:
                            return (num5 == ic2.ToSingle(null));

                        case TypeCode.Double:
                            return (num5 == ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (num5 == ic2.ToDecimal(null));
                    }
                    return false;
                }
                case TypeCode.UInt32:
                {
                    uint num6 = ic1.ToUInt32(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (num6 == ic2.ToChar(null));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (num6 == ic2.ToInt64(null));

                        case TypeCode.UInt64:
                            return (num6 == ic2.ToUInt64(null));

                        case TypeCode.Single:
                            return (num6 == ic2.ToSingle(null));

                        case TypeCode.Double:
                            return (num6 == ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (num6 == ic2.ToDecimal(null));
                    }
                    return false;
                }
                case TypeCode.Int64:
                    num7 = ic1.ToInt64(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (num7 == ic2.ToChar(null));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (num7 == ic2.ToInt64(null));

                        case TypeCode.UInt64:
                            return ((num7 >= 0L) && (num7 == ic2.ToUInt64(null)));

                        case TypeCode.Single:
                            return (num7 == ic2.ToSingle(null));

                        case TypeCode.Double:
                            return (num7 == ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (num7 == ic2.ToDecimal(null));
                    }
                    return false;

                case TypeCode.UInt64:
                {
                    ulong num8 = ic1.ToUInt64(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (num8 == ic2.ToChar(null));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            num7 = ic2.ToInt64(null);
                            return ((num7 >= 0L) && (num8 == num7));

                        case TypeCode.UInt64:
                            return (num8 == ic2.ToUInt64(null));

                        case TypeCode.Single:
                            return (num8 == ic2.ToSingle(null));

                        case TypeCode.Double:
                            return (num8 == ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (num8 == ic2.ToDecimal(null));
                    }
                    return false;
                }
                case TypeCode.Single:
                {
                    float num9 = ic1.ToSingle(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (num9 == ((float) ic2.ToChar(null)));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (num9 == ic2.ToInt64(null));

                        case TypeCode.UInt64:
                            return (num9 == ic2.ToUInt64(null));

                        case TypeCode.Single:
                            return (num9 == ic2.ToSingle(null));

                        case TypeCode.Double:
                            return (num9 == ic2.ToSingle(null));

                        case TypeCode.Decimal:
                            return (((decimal) num9) == ic2.ToDecimal(null));
                    }
                    return false;
                }
                case TypeCode.Double:
                {
                    double num10 = ic1.ToDouble(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (num10 == ((double) ic2.ToChar(null)));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (num10 == ic2.ToInt64(null));

                        case TypeCode.UInt64:
                            return (num10 == ic2.ToUInt64(null));

                        case TypeCode.Single:
                            return (((float) num10) == ic2.ToSingle(null));

                        case TypeCode.Double:
                            return (num10 == ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (((decimal) num10) == ic2.ToDecimal(null));
                    }
                    return false;
                }
                case TypeCode.Decimal:
                {
                    decimal num11 = ic1.ToDecimal(null);
                    switch (t2)
                    {
                        case TypeCode.Char:
                            return (num11 == ic2.ToChar(null));

                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (num11 == ic2.ToInt64(null));

                        case TypeCode.UInt64:
                            return (num11 == ic2.ToUInt64(null));

                        case TypeCode.Single:
                            return (num11 == ((decimal) ic2.ToSingle(null)));

                        case TypeCode.Double:
                            return (num11 == ((decimal) ic2.ToDouble(null)));

                        case TypeCode.Decimal:
                            return (num11 == ic2.ToDecimal(null));
                    }
                    return false;
                }
                case TypeCode.DateTime:
                    if (t2 != TypeCode.DateTime)
                    {
                        return false;
                    }
                    return (ic1.ToDateTime(null) == ic2.ToDateTime(null));

                case TypeCode.String:
                {
                    if (t2 != TypeCode.Char)
                    {
                        if (t2 != TypeCode.String)
                        {
                            return false;
                        }
                        if (v1 != v2)
                        {
                            return ic1.ToString(null).Equals(ic2.ToString(null));
                        }
                        return true;
                    }
                    string str2 = ic1.ToString(null);
                    if (str2.Length != 1)
                    {
                        return false;
                    }
                    return (str2[0] == ic2.ToChar(null));
                }
                default:
                    return false;
            }
            return false;
        }
Esempio n. 41
0
        internal static Object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) {
            BCLDebug.Assert(value!=null, "[Convert.DefaultToType]value!=null");

            if (targetType==null) {
                throw new ArgumentNullException("targetType");
            }
            
            if (value.GetType()==targetType) {
                return value;
            }

            if (targetType==ConvertTypes[(int)TypeCode.Boolean])
                return value.ToBoolean(provider);
            if (targetType==ConvertTypes[(int)TypeCode.Char])
                return value.ToChar(provider);
            if (targetType==ConvertTypes[(int)TypeCode.SByte])
                return value.ToSByte(provider);
            if (targetType==ConvertTypes[(int)TypeCode.Byte])
                return value.ToByte(provider);
            if (targetType==ConvertTypes[(int)TypeCode.Int16]) 
                return value.ToInt16(provider);
            if (targetType==ConvertTypes[(int)TypeCode.UInt16])
                return value.ToUInt16(provider);
            if (targetType==ConvertTypes[(int)TypeCode.Int32])
                return value.ToInt32(provider);
            if (targetType==ConvertTypes[(int)TypeCode.UInt32])
                return value.ToUInt32(provider);
            if (targetType==ConvertTypes[(int)TypeCode.Int64])
                return value.ToInt64(provider);
            if (targetType==ConvertTypes[(int)TypeCode.UInt64])
                return value.ToUInt64(provider);
            if (targetType==ConvertTypes[(int)TypeCode.Single])
                return value.ToSingle(provider);
            if (targetType==ConvertTypes[(int)TypeCode.Double])
                return value.ToDouble(provider);
            if (targetType==ConvertTypes[(int)TypeCode.Decimal])
                return value.ToDecimal(provider);
            if (targetType==ConvertTypes[(int)TypeCode.DateTime])
                return value.ToDateTime(provider);
            if (targetType==ConvertTypes[(int)TypeCode.String]) {
                return value.ToString(provider);
            }
            if (targetType==ConvertTypes[(int)TypeCode.Object])
                return (Object)value;
            if (targetType==ConvertTypes[(int)TypeCode.DBNull])
                throw new InvalidCastException(Environment.GetResourceString("InvalidCast_DBNull"));
            if (targetType==ConvertTypes[(int)TypeCode.Empty]) 
                throw new InvalidCastException(Environment.GetResourceString("InvalidCast_Empty"));
            throw new InvalidCastException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("InvalidCast_FromTo"), value.GetType().FullName, targetType.FullName));
        }
        private static void AssignTimeZone(IDateTimeResultTO dateTimeResultTo, bool assignAsTime, IConvertible value)
        {
            string lowerValue = value.ToString(CultureInfo.InvariantCulture).ToLower();

            ITimeZoneTO timeZoneTo;
            if (TimeZones.TryGetValue(lowerValue, out timeZoneTo))
            {
                dateTimeResultTo.TimeZone = timeZoneTo;
            }
        }
 internal static bool JScriptStrictEquals(Object v1, Object v2, IConvertible ic1, IConvertible ic2, TypeCode t1, TypeCode t2, bool checkForDebuggerObjects){
   switch (t1){
     case TypeCode.Empty: return t2 == TypeCode.Empty;
     case TypeCode.Object:
       if (v1 == v2) return true;
       if (v1 is Missing || v1 is System.Reflection.Missing) v1 = null;
       if (v1 == v2) return true;
       if (v2 is Missing || v2 is System.Reflection.Missing) v2 = null;
       return v1 == v2;
     case TypeCode.DBNull: return t2 == TypeCode.DBNull;
     case TypeCode.Boolean: return t2 == TypeCode.Boolean && ic1.ToBoolean(null) == ic2.ToBoolean(null);
     
     case TypeCode.Char: 
       Char ch = ic1.ToChar(null);
       switch(t2){
         case TypeCode.Char: return ch == ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64: return ch == ic2.ToInt64(null);
         case TypeCode.UInt64: return ch == ic2.ToUInt64(null);
         case TypeCode.Single: 
         case TypeCode.Double: return ch == ic2.ToDouble(null);
         case TypeCode.Decimal: return ((Decimal)(int)ch) == ic2.ToDecimal(null);
         case TypeCode.String:
           String str = ic2.ToString(null);
           return str.Length == 1 && ch == str[0];
       }
       return false;
     
     case TypeCode.SByte:
       SByte sb1 = ic1.ToSByte(null);
       switch (t2){
         case TypeCode.Char: return sb1 == ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64: return sb1 == ic2.ToInt64(null);
         case TypeCode.UInt64: return sb1 >= 0 && ((UInt64)sb1) == ic2.ToUInt64(null);
         case TypeCode.Single: return sb1 == ic2.ToSingle(null);
         case TypeCode.Double: return sb1 == ic2.ToDouble(null);
         case TypeCode.Decimal: return ((Decimal)sb1) == ic2.ToDecimal(null);
       }
       return false;
       
     case TypeCode.Byte:
       Byte b1 = ic1.ToByte(null);
       switch (t2){
         case TypeCode.Char: return b1 == ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64: return b1 == ic2.ToInt64(null);
         case TypeCode.UInt64: return b1 == ic2.ToUInt64(null);
         case TypeCode.Single: return b1 == ic2.ToSingle(null);
         case TypeCode.Double: return b1 == ic2.ToDouble(null);
         case TypeCode.Decimal: return ((Decimal)b1) == ic2.ToDecimal(null);
       }
       return false;
       
     case TypeCode.Int16:
       Int16 s1 = ic1.ToInt16(null);
       switch (t2){
         case TypeCode.Char: return s1 == ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64: return s1 == ic2.ToInt64(null);
         case TypeCode.UInt64: return s1 >= 0 && ((UInt64)s1) == ic2.ToUInt64(null);
         case TypeCode.Single: return s1 == ic2.ToSingle(null);
         case TypeCode.Double: return s1 == ic2.ToDouble(null);
         case TypeCode.Decimal: return ((Decimal)s1) == ic2.ToDecimal(null);
      }
       return false;
       
     case TypeCode.UInt16:
       UInt16 us1 = ic1.ToUInt16(null);
       switch (t2){
         case TypeCode.Char: return us1 == ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64: return us1 == ic2.ToInt64(null);
         case TypeCode.UInt64: return us1 == ic2.ToUInt64(null);
         case TypeCode.Single: return us1 == ic2.ToSingle(null);
         case TypeCode.Double: return us1 == ic2.ToDouble(null);
         case TypeCode.Decimal: return ((Decimal)us1) == ic2.ToDecimal(null);
       }
       return false;
       
     case TypeCode.Int32:
       Int32 i1 = ic1.ToInt32(null);
       switch (t2){
         case TypeCode.Char: return i1 == ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64: return i1 == ic2.ToInt64(null);
         case TypeCode.UInt64: return i1 >= 0 && ((UInt64)i1) == ic2.ToUInt64(null);
         case TypeCode.Single: return i1 == ic2.ToSingle(null);
         case TypeCode.Double: return i1 == ic2.ToDouble(null);
         case TypeCode.Decimal: return ((Decimal)i1) == ic2.ToDecimal(null);
       }
       return false;
       
     case TypeCode.UInt32:
       UInt32 ui1 = ic1.ToUInt32(null);
       switch (t2){
         case TypeCode.Char: return ui1 == ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64: return ui1 == ic2.ToInt64(null);
         case TypeCode.UInt64: return ui1 == ic2.ToUInt64(null);
         case TypeCode.Single: return ui1 == ic2.ToSingle(null);
         case TypeCode.Double: return ui1 == ic2.ToDouble(null);
         case TypeCode.Decimal: return ((Decimal)ui1) == ic2.ToDecimal(null);
       }
       return false;
       
     case TypeCode.Int64:
       Int64 l1 = ic1.ToInt64(null);
       switch (t2){
         case TypeCode.Char: return l1 == ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64: return l1 == ic2.ToInt64(null);
         case TypeCode.UInt64: return l1 >= 0 && ((UInt64)l1) == ic2.ToUInt64(null);
         case TypeCode.Single: return l1 == ic2.ToSingle(null);
         case TypeCode.Double: return l1 == ic2.ToDouble(null);
         case TypeCode.Decimal: return ((Decimal)l1) == ic2.ToDecimal(null);
       }
       return false;
       
     case TypeCode.UInt64:
       UInt64 ul1 = ic1.ToUInt64(null);
       switch (t2){
         case TypeCode.Char: return ul1 == ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64:
           l1 = ic2.ToInt64(null);
           return l1 >= 0 && ul1 == (UInt64)l1;
         case TypeCode.UInt64: return ul1 == ic2.ToUInt64(null);
         case TypeCode.Single: return ul1 == ic2.ToSingle(null);
         case TypeCode.Double: return ul1 == ic2.ToDouble(null);
         case TypeCode.Decimal: return ((Decimal)ul1) == ic2.ToDecimal(null);
       }
       return false;
       
     case TypeCode.Single:
       Single f1 = ic1.ToSingle(null);
       switch (t2){
         case TypeCode.Char: return f1 == ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64: return f1 == ic2.ToInt64(null);
         case TypeCode.UInt64: return f1 == ic2.ToUInt64(null);
         case TypeCode.Single: return f1 == ic2.ToSingle(null);
         case TypeCode.Double: return f1 == ic2.ToSingle(null);
         case TypeCode.Decimal: return ((Decimal)f1) == ic2.ToDecimal(null);
       }
       return false;
       
     case TypeCode.Double:
       Double d1 = ic1.ToDouble(null);
       switch (t2){
         case TypeCode.Char: return d1 == ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64: return d1 == ic2.ToInt64(null);
         case TypeCode.UInt64: return d1 == ic2.ToUInt64(null);
         case TypeCode.Single: return ((float)d1) == ic2.ToSingle(null);
         case TypeCode.Double: return d1 == ic2.ToDouble(null);
         case TypeCode.Decimal: return ((Decimal)d1) == ic2.ToDecimal(null);
       }
       return false;
       
     case TypeCode.Decimal:
       Decimal de1 = ic1.ToDecimal(null);
       switch (t2){
         case TypeCode.Char: return de1 == (Decimal)(int)ic2.ToChar(null);
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Int32:
         case TypeCode.UInt32:
         case TypeCode.Int64: return de1 == ic2.ToInt64(null);
         case TypeCode.UInt64: return de1 == ic2.ToUInt64(null);
         case TypeCode.Single: return de1 == (Decimal)ic2.ToSingle(null);
         case TypeCode.Double: return de1 == (Decimal)ic2.ToDouble(null);
         case TypeCode.Decimal: return de1 == ic2.ToDecimal(null);
       }
       return false;
       
     case TypeCode.DateTime: return t2 == TypeCode.DateTime && ic1.ToDateTime(null) == ic2.ToDateTime(null);
     case TypeCode.String:
       if (t2 == TypeCode.Char){
         String str = ic1.ToString(null);
         return str.Length == 1 && str[0] == ic2.ToChar(null);
       }
       return t2 == TypeCode.String && (v1 == v2 || ic1.ToString(null).Equals(ic2.ToString(null)));
   }
   return false; //should never get here
 }
Esempio n. 44
0
        public void SetAsIConvertible(IConvertible value) {
            Debug.Assert(IsEmpty); // The setter can only be called once as VariantClear might be needed otherwise

            TypeCode tc = value.GetTypeCode();
            CultureInfo ci = CultureInfo.CurrentCulture;

            switch (tc) {
                case TypeCode.Empty: break;
                case TypeCode.Object: AsUnknown = value; break;
                case TypeCode.DBNull: SetAsNull(); break;
                case TypeCode.Boolean: AsBool = value.ToBoolean(ci); break;
                case TypeCode.Char: AsUi2 = value.ToChar(ci); break;
                case TypeCode.SByte: AsI1 = value.ToSByte(ci); break;
                case TypeCode.Byte: AsUi1 = value.ToByte(ci); break;
                case TypeCode.Int16: AsI2 = value.ToInt16(ci); break;
                case TypeCode.UInt16: AsUi2 = value.ToUInt16(ci); break;
                case TypeCode.Int32: AsI4 = value.ToInt32(ci); break;
                case TypeCode.UInt32: AsUi4 = value.ToUInt32(ci); break;
                case TypeCode.Int64: AsI8 = value.ToInt64(ci); break;
                case TypeCode.UInt64: AsI8 = value.ToInt64(ci); break;
                case TypeCode.Single: AsR4 = value.ToSingle(ci); break;
                case TypeCode.Double: AsR8 = value.ToDouble(ci); break;
                case TypeCode.Decimal: AsDecimal = value.ToDecimal(ci); break;
                case TypeCode.DateTime: AsDate = value.ToDateTime(ci); break;
                case TypeCode.String: AsBstr = value.ToString(ci); break;

                default:
                    throw Assert.Unreachable;
            }
        }
Esempio n. 45
0
 internal static String ToString(Object value, PreferredType pref, IConvertible ic, bool explicitOK){
   Enum e = value as Enum;
   if (e != null) return e.ToString("G");
   EnumWrapper ew = value as EnumWrapper;
   if (ew != null) return ew.ToString();
   TypeCode code = Convert.GetTypeCode(value, ic);
   if (pref == PreferredType.LocaleString){
     switch (code){
       case TypeCode.SByte:
       case TypeCode.Byte:
       case TypeCode.Int16:
       case TypeCode.UInt16:
       case TypeCode.Int32:
       case TypeCode.UInt32:
       case TypeCode.Single:
       case TypeCode.Double: {
         double d = ic.ToDouble(null);
         return d.ToString(d <= -1e+15 || d >= 1e+15 ? "g" : "n", NumberFormatInfo.CurrentInfo);
       }
       case TypeCode.Int64: return ic.ToInt64(null).ToString("n", NumberFormatInfo.CurrentInfo);
       case TypeCode.UInt64: return ic.ToUInt64(null).ToString("n", NumberFormatInfo.CurrentInfo);
       case TypeCode.Decimal: return ic.ToDecimal(null).ToString("n", NumberFormatInfo.CurrentInfo);
     }
   }
   switch (code){
     case TypeCode.Empty: return explicitOK ? "undefined" : null;
     case TypeCode.Object: return Convert.ToString(Convert.ToPrimitive(value, pref, ref ic), ic);
     case TypeCode.DBNull: return explicitOK ? "null" : null;
     case TypeCode.Boolean: return ic.ToBoolean(null) ? "true" : "false";
     case TypeCode.Char:
     case TypeCode.SByte:
     case TypeCode.Byte:
     case TypeCode.Int16:
     case TypeCode.UInt16:
     case TypeCode.Int32:
     case TypeCode.UInt32:
     case TypeCode.Int64:
     case TypeCode.UInt64:
     case TypeCode.Decimal:
     case TypeCode.String: return ic.ToString(null);
     case TypeCode.DateTime: return Convert.ToString(DateConstructor.ob.Construct(ic.ToDateTime(null)));
     case TypeCode.Single:
     case TypeCode.Double: return Convert.ToString(ic.ToDouble(null));
   }
   return null; //Should never get here
 }
Esempio n. 46
0
 public static Literal DoAddOvf(IConvertible ic1, IConvertible ic2, TypeCode code1, TypeCode code2, BinaryExpression binaryExpression){
   TypeNode type = SystemTypes.Object;
   object val = null;
   checked{switch(code1){
     case TypeCode.SByte:
     case TypeCode.Int16:
     case TypeCode.Int32:
       int i = ic1.ToInt32(null);
       switch(code2){
         case TypeCode.SByte:
         case TypeCode.Int16:
         case TypeCode.Int32: 
         case TypeCode.Byte:
         case TypeCode.Char:
         case TypeCode.UInt16:
           val = i + ic2.ToInt32(null); 
           type = SystemTypes.Int32;
           break;
         case TypeCode.Int64: 
         case TypeCode.UInt32: 
         case TypeCode.UInt64: 
           val = i + ic2.ToInt64(null); 
           type = SystemTypes.Int64;
           break;
         case TypeCode.Single: 
           val = i + ic2.ToSingle(null); 
           type = SystemTypes.Single;
           break;
         case TypeCode.Double: 
           val = i + ic2.ToDouble(null); 
           type = SystemTypes.Double;
           break;
         case TypeCode.Decimal:
           val = i + ic2.ToDecimal(null);
           type = SystemTypes.Decimal;
           break;
         default: return null;
       }
       break;
     case TypeCode.Byte:
     case TypeCode.UInt16:
       ushort us = ic1.ToUInt16(null);
       switch(code2){
         case TypeCode.SByte:
         case TypeCode.Int16:
         case TypeCode.Int32: 
           val = us + ic2.ToInt32(null); 
           type = SystemTypes.Int32;
           break;
         case TypeCode.Byte:
         case TypeCode.UInt16:
         case TypeCode.Char:
         case TypeCode.UInt32: 
           val = us + ic2.ToUInt32(null); 
           type = SystemTypes.UInt32;
           break;
         case TypeCode.Int64: 
           val = us + ic2.ToInt64(null); 
           type = SystemTypes.Int64;
           break;
         case TypeCode.UInt64: 
           val = us + ic2.ToUInt64(null); 
           type = SystemTypes.UInt64;
           break;
         case TypeCode.Single: 
           val = us + ic2.ToSingle(null); 
           type = SystemTypes.Single;
           break;
         case TypeCode.Double: 
           val = us + ic2.ToDouble(null); 
           type = SystemTypes.Double;
           break;
         case TypeCode.Decimal:
           val = us + ic2.ToDecimal(null);
           type = SystemTypes.Decimal;
           break;
         default: return null;
       }
       break;
     case TypeCode.UInt32:
       uint ui = ic1.ToUInt32(null);
       switch(code2){
         case TypeCode.SByte:
         case TypeCode.Int16:
         case TypeCode.Int32: 
         case TypeCode.Int64: 
           val = ui + ic2.ToInt64(null); 
           type = SystemTypes.Int64;
           break;
         case TypeCode.Byte:
         case TypeCode.UInt16:
         case TypeCode.Char:
         case TypeCode.UInt32: 
           val = ui + ic2.ToUInt32(null); 
           type = SystemTypes.UInt32;
           break;
         case TypeCode.UInt64: 
           val = ui + ic2.ToUInt64(null); 
           type = SystemTypes.UInt64;
           break;
         case TypeCode.Single: 
           val = ui + ic2.ToSingle(null); 
           type = SystemTypes.Single;
           break;
         case TypeCode.Double: 
           val = ui + ic2.ToDouble(null); 
           type = SystemTypes.Double;
           break;
         case TypeCode.Decimal:
           val = ui + ic2.ToDecimal(null);
           type = SystemTypes.Decimal;
           break;
         default: return null;
       }
       break;
     case TypeCode.Int64:
       long l = ic1.ToInt64(null);
       switch(code2){
         case TypeCode.SByte:
         case TypeCode.Int16:
         case TypeCode.Int32: 
         case TypeCode.Int64: 
           val = l + ic2.ToInt64(null); 
           type = SystemTypes.Int64;
           break;
         case TypeCode.Byte:
         case TypeCode.UInt16:
         case TypeCode.Char:
         case TypeCode.UInt32: 
           val = l + ic2.ToUInt32(null); 
           type = SystemTypes.UInt32;
           break;
         case TypeCode.UInt64: 
           if (l >= 0){
             val = ((ulong)l) + ic2.ToUInt64(null);
             type = SystemTypes.UInt64;
           }else{
             val = l + (long)ic2.ToUInt64(null); 
             type = SystemTypes.Int64;
           }
           break;
         case TypeCode.Single: 
           val = l + ic2.ToSingle(null); 
           type = SystemTypes.Single;
           break;
         case TypeCode.Double: 
           val = l + ic2.ToDouble(null); 
           type = SystemTypes.Double;
           break;
         case TypeCode.Decimal:
           val = l + ic2.ToDecimal(null);
           type = SystemTypes.Decimal;
           break;
         default: return null;
       }
       break;
     case TypeCode.UInt64:
       ulong ul = ic1.ToUInt64(null);
       switch(code2){
         case TypeCode.SByte:
         case TypeCode.Int16:
         case TypeCode.Int32: 
         case TypeCode.Byte:
         case TypeCode.UInt16:
         case TypeCode.Char:
         case TypeCode.UInt32: 
           val = ul + ic2.ToUInt32(null); 
           type = SystemTypes.UInt32;
           break;
         case TypeCode.Int64: 
         case TypeCode.UInt64: 
           val = ul + ic2.ToUInt64(null); 
           type = SystemTypes.UInt64;
           break;
         case TypeCode.Single: 
           val = ul + ic2.ToSingle(null); 
           type = SystemTypes.Single;
           break;
         case TypeCode.Double: 
           val = ul + ic2.ToDouble(null); 
           type = SystemTypes.Double;
           break;
         case TypeCode.Decimal:
           val = ul + ic2.ToDecimal(null);
           type = SystemTypes.Decimal;
           break;
         default: return null;
       }
       break;
     case TypeCode.Single:
       float f = ic1.ToSingle(null);
       switch(code2){
         case TypeCode.SByte:
         case TypeCode.Int16:
           val = f + ic2.ToInt16(null);
           type = SystemTypes.Single;
           break;
         case TypeCode.Int32: 
         case TypeCode.Int64: 
           val = f + (double)ic2.ToInt64(null); 
           type = SystemTypes.Double;
           break;
         case TypeCode.Byte:
         case TypeCode.Char:
         case TypeCode.UInt16:
           val = f + ic2.ToUInt16(null); 
           type = SystemTypes.Single;
           break;
         case TypeCode.UInt32: 
         case TypeCode.UInt64: 
           val = f + (double)ic2.ToUInt64(null); 
           type = SystemTypes.Double;
           break;
         case TypeCode.Single: 
         case TypeCode.Double: 
           val = f + ic2.ToDouble(null); 
           type = SystemTypes.Double;
           break;
         case TypeCode.Decimal:
           val = f + (double)ic2.ToDecimal(null);
           type = SystemTypes.Double;
           break;
         default: return null;
       }
       break;
     case TypeCode.Double:
       double d = ic1.ToDouble(null);
       switch(code2){
         case TypeCode.SByte:
         case TypeCode.Int16:
         case TypeCode.Int32: 
         case TypeCode.Int64: 
           val = d + ic2.ToInt64(null); 
           type = SystemTypes.Double;
           break;
         case TypeCode.Byte:
         case TypeCode.Char:
         case TypeCode.UInt16:
         case TypeCode.UInt32: 
         case TypeCode.UInt64: 
           val = d + ic2.ToUInt64(null); 
           type = SystemTypes.Double;
           break;
         case TypeCode.Single: 
         case TypeCode.Double: 
           val = d + ic2.ToDouble(null); 
           type = SystemTypes.Double;
           break;
         case TypeCode.Decimal:
           val = d + (double)ic2.ToDecimal(null);
           type = SystemTypes.Double;
           break;
         default: return null;
       }
       break;
     case TypeCode.Decimal:
       decimal dec = ic1.ToDecimal(null);
       switch(code2){
         case TypeCode.SByte:
         case TypeCode.Byte:
         case TypeCode.Int16:
         case TypeCode.UInt16:
         case TypeCode.Char:
         case TypeCode.Int32: 
           val = dec + ic2.ToInt32(null); 
           type = SystemTypes.Decimal;
           break;
         case TypeCode.UInt32: 
         case TypeCode.Int64: 
         case TypeCode.UInt64: 
           val = dec + ic2.ToInt64(null); 
           type = SystemTypes.Decimal;
           break;
         case TypeCode.Decimal:
           val = dec + ic2.ToDecimal(null);
           type = SystemTypes.Decimal;
           break;
         default: return null;
       }
       break;
     case TypeCode.String:
       string str = ic1.ToString(null);
       switch (code2) {
         case TypeCode.String:
           val = str + ic2.ToString(null);
           type = SystemTypes.String;
           break;
         default: return null;
       }
       break;
     default: return null;
   }}
   return new Literal(val, type, binaryExpression.SourceContext);
 }
Esempio n. 47
0
	// Default implementation of the "ToType" methods in
	// the primitive classes like Byte, Int32, Boolean, etc.
	internal static Object DefaultToType(IConvertible obj, Type targetType,
										 IFormatProvider provider,
										 bool recursive)
			{
				if(targetType != null)
				{
					if(obj.GetType() == targetType)
					{
						return obj;
					}
					else if(targetType == ConvertTypes[(int)TypeCode.Boolean])
					{
						return (Object)(obj.ToBoolean(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.Char])
					{
						return (Object)(obj.ToChar(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.SByte])
					{
						return (Object)(obj.ToSByte(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.Byte])
					{
						return (Object)(obj.ToByte(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.Int16])
					{
						return (Object)(obj.ToInt16(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.UInt16])
					{
						return (Object)(obj.ToUInt16(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.Int32])
					{
						return (Object)(obj.ToInt32(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.UInt32])
					{
						return (Object)(obj.ToUInt32(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.Int64])
					{
						return (Object)(obj.ToInt64(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.UInt64])
					{
						return (Object)(obj.ToUInt64(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.Single])
					{
						return (Object)(obj.ToSingle(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.Double])
					{
						return (Object)(obj.ToDouble(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.Decimal])
					{
						return (Object)(obj.ToDecimal(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.DateTime])
					{
						return (Object)(obj.ToDateTime(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.String])
					{
						return (Object)(obj.ToString(provider));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.Object])
					{
						return obj;
					}
					else if(targetType == ConvertTypes[(int)TypeCode.Empty])
					{
						throw new InvalidCastException
							(_("InvalidCast_Empty"));
					}
					else if(targetType == ConvertTypes[(int)TypeCode.DBNull])
					{
						throw new InvalidCastException
							(_("InvalidCast_DBNull"));
					}
					else if(recursive)
					{
						throw new InvalidCastException
							(String.Format
								(_("InvalidCast_FromTo"),
		 					     obj.GetType().FullName, targetType.FullName));
					}
					else
					{
						// We weren't called from a "ToType" method,
						// so we can use it to handle the default case.
						return obj.ToType(targetType, provider);
					}
				}
				else
				{
					throw new ArgumentNullException("targetType");
				}
			}
Esempio n. 48
0
 private static bool JScriptEquals(Object v1, Object v2, IConvertible ic1, IConvertible ic2, TypeCode t1, TypeCode t2, bool checkForDebuggerObjects){
   if (StrictEquality.JScriptStrictEquals(v1, v2, ic1, ic2, t1, t2, checkForDebuggerObjects))
     return true;
   if (t2 == TypeCode.Boolean){
     v2 = ic2.ToBoolean(null) ? 1 : 0;
     ic2 = Convert.GetIConvertible(v2);
     return Equality.JScriptEquals(v1, v2, ic1, ic2, t1, TypeCode.Int32, false);
   }
   switch (t1){
     case TypeCode.Empty: return t2 == TypeCode.Empty || t2 == TypeCode.DBNull || (t2 == TypeCode.Object && v2 is Missing);
     case TypeCode.Object:
       switch (t2){
         case TypeCode.Empty:
         case TypeCode.DBNull:
           return v1 is Missing;
         case TypeCode.Char:
         case TypeCode.SByte: 
         case TypeCode.Byte: 
         case TypeCode.Int16: 
         case TypeCode.UInt16: 
         case TypeCode.Int32: 
         case TypeCode.UInt32: 
         case TypeCode.Int64: 
         case TypeCode.UInt64: 
         case TypeCode.Single: 
         case TypeCode.Double: 
         case TypeCode.Decimal:
         case TypeCode.String:
           IConvertible pvic1 = ic1;
           Object pv1 = Convert.ToPrimitive(v1, PreferredType.Either, ref pvic1);
           if (pvic1 != null && pv1 != v1)
             return Equality.JScriptEquals(pv1, v2, pvic1, ic2, pvic1.GetTypeCode(), t2, false);
           else
             return false;
       }
       return false;
     case TypeCode.DBNull: return t2 == TypeCode.DBNull || t2 == TypeCode.Empty || (t2 == TypeCode.Object && v2 is Missing);
     case TypeCode.Boolean:
       v1 = ic1.ToBoolean(null) ? 1 : 0;
       ic1 = Convert.GetIConvertible(v1);
       return Equality.JScriptEquals(v1, v2, ic1, ic2, TypeCode.Int32, t2, false);
     case TypeCode.Char:
     case TypeCode.SByte:
     case TypeCode.Byte:
     case TypeCode.Int16:
     case TypeCode.UInt16:
     case TypeCode.Int32:
     case TypeCode.UInt32:
     case TypeCode.Int64:
     case TypeCode.UInt64:
     case TypeCode.Single:
     case TypeCode.Double:
     case TypeCode.Decimal:
       if (t2 == TypeCode.Object){
         IConvertible pvic2 = ic2;
         Object pv2 = Convert.ToPrimitive(v2, PreferredType.Either, ref pvic2);
         if (pvic2 != null && pv2 != v2)
           return Equality.JScriptEquals(v1, pv2, ic1, pvic2, t1, pvic2.GetTypeCode(), false);
         else
           return false;
       }
       if (t2 == TypeCode.String){
         if (v1 is Enum) return Convert.ToString(v1).Equals(ic2.ToString(null));
         v2 = Convert.ToNumber(v2, ic2);
         ic2 = Convert.GetIConvertible(v2);
         return StrictEquality.JScriptStrictEquals(v1, v2, ic1, ic2, t1, TypeCode.Double, false);
       }
       return false;
     case TypeCode.DateTime:
       if (t2 == TypeCode.Object){
         IConvertible pvic2 = ic2;
         Object pv2 = Convert.ToPrimitive(v2, PreferredType.Either, ref pvic2);
         if (pv2 != null && pv2 != v2)
           return StrictEquality.JScriptStrictEquals(v1, pv2, ic1, pvic2, t1, pvic2.GetTypeCode(), false);
       }
       return false;
     case TypeCode.String:
       switch (t2){
         case TypeCode.Object:{
           IConvertible pvic2 = ic2;
           Object pv2 = Convert.ToPrimitive(v2, PreferredType.Either, ref pvic2);
           if (pvic2 != null && pv2 != v2)
             return Equality.JScriptEquals(v1, pv2, ic1, pvic2, t1, pvic2.GetTypeCode(), false);
           else
             return false;
         }
         case TypeCode.SByte: 
         case TypeCode.Byte: 
         case TypeCode.Int16: 
         case TypeCode.UInt16: 
         case TypeCode.Int32: 
         case TypeCode.UInt32: 
         case TypeCode.Int64: 
         case TypeCode.UInt64: 
         case TypeCode.Single: 
         case TypeCode.Double: 
         case TypeCode.Decimal:
           if (v2 is Enum) return Convert.ToString(v2).Equals(ic1.ToString(null));
           v1 = Convert.ToNumber(v1, ic1);
           ic1 = Convert.GetIConvertible(v1);
           return StrictEquality.JScriptStrictEquals(v1, v2, ic1, ic2, TypeCode.Double, t2, false);
       }
       return false;
   }
   return false;
 }
Esempio n. 49
0
 private void WriteNumber(IConvertible number)
 {
   _builder.Append(number.ToString(NumberFormatInfo.InvariantInfo));
 }
Esempio n. 50
0
 public static void WriteIConvertible(IConvertible input)
 {
     Console.WriteLine("{0}: {1}", input.GetTypeCode(), input.ToString(null).ToLower());
 }
Esempio n. 51
0
		internal static object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
		{
			if (targetType == null)
			{
				throw new ArgumentNullException("targetType");
			}
			RuntimeType left = targetType as RuntimeType;
			if (left != null)
			{
				if (value.GetType() == targetType)
				{
					return value;
				}
				if (left == Convert.ConvertTypes[3])
				{
					return value.ToBoolean(provider);
				}
				if (left == Convert.ConvertTypes[4])
				{
					return value.ToChar(provider);
				}
				if (left == Convert.ConvertTypes[5])
				{
					return value.ToSByte(provider);
				}
				if (left == Convert.ConvertTypes[6])
				{
					return value.ToByte(provider);
				}
				if (left == Convert.ConvertTypes[7])
				{
					return value.ToInt16(provider);
				}
				if (left == Convert.ConvertTypes[8])
				{
					return value.ToUInt16(provider);
				}
				if (left == Convert.ConvertTypes[9])
				{
					return value.ToInt32(provider);
				}
				if (left == Convert.ConvertTypes[10])
				{
					return value.ToUInt32(provider);
				}
				if (left == Convert.ConvertTypes[11])
				{
					return value.ToInt64(provider);
				}
				if (left == Convert.ConvertTypes[12])
				{
					return value.ToUInt64(provider);
				}
				if (left == Convert.ConvertTypes[13])
				{
					return value.ToSingle(provider);
				}
				if (left == Convert.ConvertTypes[14])
				{
					return value.ToDouble(provider);
				}
				if (left == Convert.ConvertTypes[15])
				{
					return value.ToDecimal(provider);
				}
				if (left == Convert.ConvertTypes[16])
				{
					return value.ToDateTime(provider);
				}
				if (left == Convert.ConvertTypes[18])
				{
					return value.ToString(provider);
				}
				if (left == Convert.ConvertTypes[1])
				{
					return value;
				}
				if (left == Convert.EnumType)
				{
					return (Enum)value;
				}
				if (left == Convert.ConvertTypes[2])
				{
					throw new InvalidCastException(Environment.GetResourceString("InvalidCast_DBNull"));
				}
				if (left == Convert.ConvertTypes[0])
				{
					throw new InvalidCastException(Environment.GetResourceString("InvalidCast_Empty"));
				}
			}
			throw new InvalidCastException(Environment.GetResourceString("InvalidCast_FromTo", new object[]
			{
				value.GetType().FullName, 
				targetType.FullName
			}));
		}
Esempio n. 52
0
 public InfluxPoint AddTag(string name, IConvertible value)
 {
     return AddRawTag(name, value.ToString(LineProtocolFormat.FormatProvider));
 }
Esempio n. 53
0
 internal static bool ToBoolean(Object value, IConvertible ic){
   switch (Convert.GetTypeCode(value, ic)){
     case TypeCode.Empty: return false;
     case TypeCode.Object:
       if (value is Missing || value is System.Reflection.Missing) return false;
       Type t = value.GetType();
       MethodInfo meth = t.GetMethod("op_True", BindingFlags.ExactBinding|BindingFlags.Public|BindingFlags.Static, null, new Type[]{t}, null);
       if (meth != null && (meth.Attributes & MethodAttributes.SpecialName) != 0 && meth.ReturnType == Typeob.Boolean){
         meth = new JSMethodInfo(meth);
         return (bool)meth.Invoke(null, BindingFlags.SuppressChangeType, null, new Object[]{value}, null);
       }
       return true;
     case TypeCode.DBNull: return false;
     case TypeCode.Boolean: return ic.ToBoolean(null);
     case TypeCode.Char: return ic.ToChar(null) != (Char)0;
     case TypeCode.SByte:
     case TypeCode.Byte:
     case TypeCode.Int16:
     case TypeCode.UInt16:
     case TypeCode.Int32: return ic.ToInt32(null) != 0;
     case TypeCode.UInt32:
     case TypeCode.Int64: return ic.ToInt64(null) != 0;
     case TypeCode.UInt64: return ic.ToUInt64(null) != 0;
     case TypeCode.Single:
     case TypeCode.Double:
       double d = ic.ToDouble(null);
       if (d != d) return false; else return d != 0;
     case TypeCode.Decimal: return ic.ToDecimal(null) != (Decimal)0;
     case TypeCode.DateTime: return true;
     case TypeCode.String: return ic.ToString(null).Length != 0;
   }
   return false; //should never get here
 }
Esempio n. 54
0
        private void SetVal(Field field, IConvertible value, bool isString = false)
        {
            if (!string.IsNullOrWhiteSpace(field.Name))
                this.valList[field.Name] = value;

            if (value == null)
                content.Append(", NULL");
            else if (!isString)
                content.Append(", " + value.ToString(CultureInfo.InvariantCulture));
            else
            {
                var val = value.ToString(CultureInfo.InvariantCulture);
                if (string.IsNullOrWhiteSpace(val))
                    content.Append(", NULL");
                else
                    content.Append(", \"" + val.Replace(@"'", @"\'").Replace("\"", "\\\"") + "\"");
            }

            if (Program.DebugOutput)
                content.Append(" /* " + field.Name + " */");
        }
Esempio n. 55
0
 internal static uint ToUint32(Object value, IConvertible ic){
   switch (Convert.GetTypeCode(value, ic)){
     case TypeCode.Empty: return 0;
     case TypeCode.DBNull: return 0;
     case TypeCode.Boolean: return ic.ToBoolean(null) ? (uint)1 : (uint)0;
     case TypeCode.Char: return (uint)ic.ToChar(null);
     case TypeCode.Byte:
     case TypeCode.UInt16:
     case TypeCode.UInt32: return ic.ToUInt32(null);
     case TypeCode.UInt64: return (uint)ic.ToUInt64(null);
     case TypeCode.SByte:
     case TypeCode.Int16:
     case TypeCode.Int32:
     case TypeCode.Int64: return (uint)ic.ToInt64(null);
     case TypeCode.Single: return (uint)ic.ToSingle(null);
     case TypeCode.Double:
     case TypeCode.Decimal: return (uint)ic.ToDouble(null);
     case TypeCode.Object:
     case TypeCode.DateTime:
       Object pval = Convert.ToPrimitive(value, PreferredType.Number, ref ic);
       if (pval != value)
         return Convert.ToUint32(pval, ic);
       else
         return 0;
     case TypeCode.String: return (uint)Convert.ToNumber(ic.ToString(null));
   }
   return 0; //should never get here
 }
 private static void AssignEra(IDateTimeResultTO dateTimeResultTo, bool assignAsTime, IConvertible value)
 {
     dateTimeResultTo.Era = value.ToString(CultureInfo.InvariantCulture);
 }
        private static void AssignAmPm(IDateTimeResultTO dateTimeResultTo, bool assignAsTime, IConvertible value)
        {
            string lowerValue = value.ToString(CultureInfo.InvariantCulture).ToLower();

            if (lowerValue == "pm" || lowerValue == "p.m" || lowerValue == "p.m.")
            {
                dateTimeResultTo.AmPm = DateTimeAmPm.pm;
            }
            else
            {
                dateTimeResultTo.AmPm = DateTimeAmPm.am;
            }
        }
 private object ExecuteMathOperator(IConvertible left, IConvertible right, CodeBinaryOperatorType op)
 {
     if (op == CodeBinaryOperatorType.Add)
     {
         string str = left as string;
         string str2 = right as string;
         if ((str == null) && (left is char))
         {
             str = left.ToString();
         }
         if ((str2 == null) && (right is char))
         {
             str2 = right.ToString();
         }
         if ((str != null) && (str2 != null))
         {
             return (str + str2);
         }
     }
     return left;
 }
        private static double JScriptCompare2(object v1, object v2, IConvertible ic1, IConvertible ic2, TypeCode t1, TypeCode t2)
        {
            double num7;
            if (t1 == TypeCode.Object)
            {
                v1 = Microsoft.JScript.Convert.ToPrimitive(v1, PreferredType.Number, ref ic1);
                t1 = Microsoft.JScript.Convert.GetTypeCode(v1, ic1);
            }
            if (t2 == TypeCode.Object)
            {
                v2 = Microsoft.JScript.Convert.ToPrimitive(v2, PreferredType.Number, ref ic2);
                t2 = Microsoft.JScript.Convert.GetTypeCode(v2, ic2);
            }
            switch (t1)
            {
                case TypeCode.Char:
                    if (t2 != TypeCode.String)
                    {
                        break;
                    }
                    return (double) string.CompareOrdinal(Microsoft.JScript.Convert.ToString(v1, ic1), ic2.ToString(null));

                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                    break;

                case TypeCode.UInt64:
                {
                    ulong num3 = ic1.ToUInt64(null);
                    switch (t2)
                    {
                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                        {
                            long num4 = ic2.ToInt64(null);
                            if (num4 < 0L)
                            {
                                return 1.0;
                            }
                            if (num3 == num4)
                            {
                                return 0.0;
                            }
                            return -1.0;
                        }
                        case TypeCode.UInt64:
                        {
                            ulong num5 = ic2.ToUInt64(null);
                            if (num3 < num5)
                            {
                                return -1.0;
                            }
                            if (num3 == num5)
                            {
                                return 0.0;
                            }
                            return 1.0;
                        }
                        case TypeCode.Single:
                        case TypeCode.Double:
                            return (num3 - ic2.ToDouble(null));

                        case TypeCode.Decimal:
                            return (double) (new decimal(num3) - ic2.ToDecimal(null));
                    }
                    object obj3 = Microsoft.JScript.Convert.ToNumber(v2, ic2);
                    return JScriptCompare2(v1, obj3, ic1, Microsoft.JScript.Convert.GetIConvertible(obj3), t1, TypeCode.Double);
                }
                case TypeCode.Decimal:
                {
                    decimal num6 = ic1.ToDecimal(null);
                    switch (t2)
                    {
                        case TypeCode.SByte:
                        case TypeCode.Byte:
                        case TypeCode.Int16:
                        case TypeCode.UInt16:
                        case TypeCode.Int32:
                        case TypeCode.UInt32:
                        case TypeCode.Int64:
                            return (double) (num6 - new decimal(ic2.ToInt64(null)));

                        case TypeCode.UInt64:
                            return (double) (num6 - new decimal(ic2.ToUInt64(null)));

                        case TypeCode.Single:
                        case TypeCode.Double:
                            return (double) (num6 - new decimal(ic2.ToDouble(null)));

                        case TypeCode.Decimal:
                            return (double) (num6 - ic2.ToDecimal(null));
                    }
                    return (double) (num6 - new decimal(Microsoft.JScript.Convert.ToNumber(v2, ic2)));
                }
                case TypeCode.String:
                {
                    TypeCode code5 = t2;
                    if (code5 == TypeCode.Char)
                    {
                        return (double) string.CompareOrdinal(ic1.ToString(null), Microsoft.JScript.Convert.ToString(v2, ic2));
                    }
                    if (code5 != TypeCode.String)
                    {
                        goto Label_0355;
                    }
                    return (double) string.CompareOrdinal(ic1.ToString(null), ic2.ToString(null));
                }
                default:
                    goto Label_0355;
            }
            long num = ic1.ToInt64(null);
            switch (t2)
            {
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                    return (double) (num - ic2.ToInt64(null));

                case TypeCode.UInt64:
                    if (num >= 0L)
                    {
                        ulong num2 = ic2.ToUInt64(null);
                        if (num < num2)
                        {
                            return -1.0;
                        }
                        if (num == num2)
                        {
                            return 0.0;
                        }
                        return 1.0;
                    }
                    return -1.0;

                case TypeCode.Single:
                case TypeCode.Double:
                    return (num - ic2.ToDouble(null));

                case TypeCode.Decimal:
                    return (double) (new decimal(num) - ic2.ToDecimal(null));

                default:
                {
                    object obj2 = Microsoft.JScript.Convert.ToNumber(v2, ic2);
                    return JScriptCompare2(v1, obj2, ic1, Microsoft.JScript.Convert.GetIConvertible(obj2), t1, TypeCode.Double);
                }
            }
        Label_0355:
            num7 = Microsoft.JScript.Convert.ToNumber(v1, ic1);
            double num8 = Microsoft.JScript.Convert.ToNumber(v2, ic2);
            if (num7 == num8)
            {
                return 0.0;
            }
            return (num7 - num8);
        }
Esempio n. 60
0
		private static bool ToBoolean (object value, bool explicitConversion, IConvertible convertible)
		{
			TypeCode preferredType = GetTypeCode (value, convertible);
			switch (preferredType) {
					//undefined & null
				case TypeCode.Empty:
				case TypeCode.DBNull:
					return false;

				case TypeCode.Boolean:
					return convertible.ToBoolean (null);

				case TypeCode.Byte:
				case TypeCode.Char:
				case TypeCode.Decimal:
				case TypeCode.Double:
				case TypeCode.Int16:
				case TypeCode.Int32:
				case TypeCode.Int64:
				case TypeCode.SByte:
				case TypeCode.Single:
				case TypeCode.UInt16:
				case TypeCode.UInt32:
				case TypeCode.UInt64:
					double d = convertible.ToDouble (null);
					return ((d != 0.0) && !double.IsNaN (d));
				case TypeCode.String:
					string str = convertible.ToString ();
					return str.Length != 0;
				case TypeCode.Object:
					return true;

				//TODO datetime find behaviour maybe as a number
				case TypeCode.DateTime:
					return true;
								
			}
			throw new NotImplementedException ();
		}