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


C# IConvertible.ToInt64方法代码示例

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


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

示例1: ToBoolean

        internal static bool ToBoolean(object value, IConvertible ic)
        {
            switch (GetTypeCode(value, ic))
            {
                case TypeCode.Empty:
                    return false;

                case TypeCode.Object:
                {
                    if ((value is Microsoft.JScript.Missing) || (value is System.Reflection.Missing))
                    {
                        return false;
                    }
                    Type type = value.GetType();
                    MethodInfo method = type.GetMethod("op_True", BindingFlags.ExactBinding | BindingFlags.Public | BindingFlags.Static, null, new Type[] { type }, null);
                    if (((method != null) && ((method.Attributes & MethodAttributes.SpecialName) != MethodAttributes.PrivateScope)) && (method.ReturnType == typeof(bool)))
                    {
                        method = new JSMethodInfo(method);
                        return (bool) method.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) != '\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) != 0L);

                case TypeCode.UInt64:
                    return (ic.ToUInt64(null) != 0L);

                case TypeCode.Single:
                case TypeCode.Double:
                {
                    double num = ic.ToDouble(null);
                    return ((num == num) && !(num == 0.0));
                }
                case TypeCode.Decimal:
                    return (ic.ToDecimal(null) != 0M);

                case TypeCode.DateTime:
                    return true;

                case TypeCode.String:
                    return (ic.ToString(null).Length != 0);
            }
            return false;
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:62,代码来源:Convert.cs

示例2: ToString

 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
 }
开发者ID:ArildF,项目名称:masters,代码行数:46,代码来源:convert.cs

示例3: SetAsIConvertible

        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;
            }
        }
开发者ID:andreakn,项目名称:ironruby,代码行数:30,代码来源:Variant.cs

示例4: DoSubOvf

 public static Literal DoSubOvf(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: 
         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.Char:
       char ch = ic1.ToChar(null);
       if (code2 != TypeCode.Char) goto default;
       val = ch - ic2.ToChar(null);
       type = SystemTypes.Int32;
       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: 
//.........这里部分代码省略.........
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:101,代码来源:Evaluator.cs

示例5: DoDiv

 public static Literal DoDiv(IConvertible ic1, IConvertible ic2, TypeCode code1, TypeCode code2, BinaryExpression binaryExpression){
   TypeNode type = SystemTypes.Object;
   object val = null;
   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: 
         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;
//.........这里部分代码省略.........
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:101,代码来源:Evaluator.cs

示例6: DefaultToType

		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
			}));
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:96,代码来源:Convert.cs

示例7: DoOr

 public static Literal DoOr(IConvertible ic1, IConvertible ic2, TypeCode code1, TypeCode code2, BinaryExpression binaryExpression){
   TypeNode type = SystemTypes.Object;
   object val = null;
   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.UInt32: 
           if (i >= 0){
             val = ((uint)i) | ic2.ToUInt32(null); 
             type = SystemTypes.UInt32;
             break;
           }
           goto case TypeCode.Int64;
         case TypeCode.Int64: 
           long lng = i;
           val = lng | ic2.ToInt64(null); 
           type = SystemTypes.Int64;
           break;
         case TypeCode.UInt64: 
           ulong ulng = (ulong) i;
           val = ulng | ic2.ToUInt64(null); 
           type = SystemTypes.UInt64;
           break;
         case TypeCode.Single: 
         case TypeCode.Double: 
         case TypeCode.Decimal:
           return null;
         default: return null;
       }
       break;
     case TypeCode.Byte:
     case TypeCode.Char:
     case TypeCode.UInt16:
       ushort us = ic1.ToUInt16(null);
       switch(code2){
         case TypeCode.SByte:
         case TypeCode.Int16:
         case TypeCode.Int32: 
         case TypeCode.Byte:
         case TypeCode.UInt16:
         case TypeCode.Char:
           val = ((int)us) | ic2.ToInt32(null); 
           type = SystemTypes.Int32;
           break;
         case TypeCode.UInt32: 
           val = ((uint)us) | ic2.ToUInt32(null); 
           type = SystemTypes.UInt32;
           break;
         case TypeCode.Int64: 
           val = ((long)us) | ic2.ToInt64(null); 
           type = SystemTypes.Int64;
           break;
         case TypeCode.UInt64: 
           val = ((ulong)us) | ic2.ToUInt64(null); 
           type = SystemTypes.UInt64;
           break;
         case TypeCode.Single: 
         case TypeCode.Double: 
         case TypeCode.Decimal:
           return null;
         default: return null;
       }
       break;
     case TypeCode.UInt32:
       uint ui = ic1.ToUInt32(null);
       switch(code2){
         case TypeCode.SByte:
         case TypeCode.Int16:
         case TypeCode.Int32: 
           i = ic2.ToInt32(null);
           if (i >= 0){
             val = ui | (uint)i;
             type = SystemTypes.UInt32;
             break;
           }
           goto case TypeCode.Int64;
         case TypeCode.Int64: 
           val = ((long)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: 
//.........这里部分代码省略.........
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:101,代码来源:Evaluator.cs

示例8: ExecuteBinaryOperator


//.........这里部分代码省略.........
             char ch2 = right.ToChar(null);
             if (op != CodeBinaryOperatorType.BitwiseOr)
             {
                 obj2 = ch & ch2;
                 break;
             }
             obj2 = ch | ch2;
             break;
         }
         case TypeCode.Byte:
         {
             byte num5 = left.ToByte(null);
             byte num6 = right.ToByte(null);
             if (op != CodeBinaryOperatorType.BitwiseOr)
             {
                 obj2 = num5 & num6;
                 break;
             }
             obj2 = num5 | num6;
             break;
         }
         case TypeCode.Int16:
         {
             short num7 = left.ToInt16(null);
             short num8 = right.ToInt16(null);
             if (op != CodeBinaryOperatorType.BitwiseOr)
             {
                 obj2 = num7 & num8;
                 break;
             }
             obj2 = (short) (((ushort) num7) | ((ushort) num8));
             break;
         }
         case TypeCode.UInt16:
         {
             ushort num9 = left.ToUInt16(null);
             ushort num10 = right.ToUInt16(null);
             if (op != CodeBinaryOperatorType.BitwiseOr)
             {
                 obj2 = num9 & num10;
                 break;
             }
             obj2 = num9 | num10;
             break;
         }
         case TypeCode.Int32:
         {
             int num11 = left.ToInt32(null);
             int num12 = right.ToInt32(null);
             if (op != CodeBinaryOperatorType.BitwiseOr)
             {
                 obj2 = num11 & num12;
                 break;
             }
             obj2 = num11 | num12;
             break;
         }
         case TypeCode.UInt32:
         {
             uint num13 = left.ToUInt32(null);
             uint num14 = right.ToUInt32(null);
             if (op != CodeBinaryOperatorType.BitwiseOr)
             {
                 obj2 = num13 & num14;
                 break;
             }
             obj2 = num13 | num14;
             break;
         }
         case TypeCode.Int64:
         {
             long num15 = left.ToInt64(null);
             long num16 = right.ToInt64(null);
             if (op != CodeBinaryOperatorType.BitwiseOr)
             {
                 obj2 = num15 & num16;
                 break;
             }
             obj2 = num15 | num16;
             break;
         }
         case TypeCode.UInt64:
         {
             ulong num17 = left.ToUInt64(null);
             ulong num18 = right.ToUInt64(null);
             if (op != CodeBinaryOperatorType.BitwiseOr)
             {
                 obj2 = num17 & num18;
                 break;
             }
             obj2 = num17 | num18;
             break;
         }
     }
     if ((obj2 != left) && (left is Enum))
     {
         obj2 = Enum.ToObject(left.GetType(), obj2);
     }
     return obj2;
 }
开发者ID:Reegenerator,项目名称:Sample-CustomizeDatasetCS,代码行数:101,代码来源:CodeDomSerializerBase.cs

示例9: JScriptStrictEquals

 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);
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:strictequality.cs

示例10: GetNumberFormat

            private NumberFormat GetNumberFormat(IConvertible value)
            {
                NumberFormat format = this.numberFormat;
                if (format == NumberFormat.Auto)
                {
                    long number = (value is ulong) ? (long)(ulong)value : value.ToInt64(CultureInfo.InvariantCulture);

                    if (number < 16)
                    {
                        return NumberFormat.Decimal;
                    }

                    if (((number % 10) == 0) && (number < 1000))
                    {
                        return NumberFormat.Decimal;
                    }

                    return NumberFormat.Hexadecimal;
                }

                return format;
            }
开发者ID:jorik041,项目名称:JavaScriptLanguage,代码行数:22,代码来源:JavaScriptLanguage.cs

示例11: EncodeConvertible

        protected void EncodeConvertible(IConvertible value, Stream output)
        {
            output.WriteByte((byte)value.GetTypeCode());
            byte[] result;
            switch (value.GetTypeCode())
            {
            // the following encode directly on the stream
            case TypeCode.Boolean: output.WriteByte((byte)((bool)value ? 1 : 0)); return;
            case TypeCode.Byte: output.WriteByte(value.ToByte(null)); return;
            case TypeCode.SByte: output.WriteByte((byte)(value.ToSByte(null) + 128)); return;

            case TypeCode.Object:
                formatter.Serialize(output, value);
                return;

            case TypeCode.String: {
                long lengthPosition = output.Position;
                output.Write(new byte[4], 0, 4);
                StreamWriter w = new StreamWriter(output, Encoding.UTF8);
                w.Write((string)value);
                w.Flush();
                long savedPosition = output.Position;
                uint payloadLength = (uint)(output.Position - lengthPosition - 4);
                output.Position = lengthPosition;
                output.Write(DataConverter.Converter.GetBytes(payloadLength), 0, 4);
                output.Position = savedPosition;
                return;
            }

            // the following obtain byte arrays which are dumped below
            case TypeCode.Char: result = DataConverter.Converter.GetBytes(value.ToChar(null)); break;
            case TypeCode.Single: result = DataConverter.Converter.GetBytes(value.ToSingle(null)); break;
            case TypeCode.Double: result = DataConverter.Converter.GetBytes(value.ToDouble(null)); break;
            case TypeCode.Int16: result = DataConverter.Converter.GetBytes(value.ToInt16(null)); break;
            case TypeCode.Int32: result = DataConverter.Converter.GetBytes(value.ToInt32(null)); break;
            case TypeCode.Int64: result = DataConverter.Converter.GetBytes(value.ToInt64(null)); break;
            case TypeCode.UInt16: result = DataConverter.Converter.GetBytes(value.ToUInt16(null)); break;
            case TypeCode.UInt32: result = DataConverter.Converter.GetBytes(value.ToUInt32(null)); break;
            case TypeCode.UInt64: result = DataConverter.Converter.GetBytes(value.ToUInt64(null)); break;
            case TypeCode.DateTime: result = DataConverter.Converter.GetBytes(((DateTime)value).ToBinary()); break;

            default: throw new MarshallingException("Unhandled form of IConvertible: " + value.GetTypeCode());
            }
            output.Write(result, 0, result.Length);
        }
开发者ID:pichiliani,项目名称:CoMusic,代码行数:45,代码来源:Marshalling.cs

示例12: ToUint32

        internal static uint ToUint32(object value, IConvertible ic)
        {
            switch (GetTypeCode(value, ic))
            {
                case TypeCode.Empty:
                    return 0;

                case TypeCode.Object:
                case TypeCode.DateTime:
                {
                    object obj2 = ToPrimitive(value, PreferredType.Number, ref ic);
                    if (obj2 == value)
                    {
                        return 0;
                    }
                    return ToUint32(obj2, ic);
                }
                case TypeCode.DBNull:
                    return 0;

                case TypeCode.Boolean:
                    if (ic.ToBoolean(null))
                    {
                        return 1;
                    }
                    return 0;

                case TypeCode.Char:
                    return ic.ToChar(null);

                case TypeCode.SByte:
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                    return (uint) ic.ToInt64(null);

                case TypeCode.Byte:
                case TypeCode.UInt16:
                case TypeCode.UInt32:
                    return ic.ToUInt32(null);

                case TypeCode.UInt64:
                    return (uint) ic.ToUInt64(null);

                case TypeCode.Single:
                case TypeCode.Double:
                    return (uint) Runtime.DoubleToInt64(ic.ToDouble(null));

                case TypeCode.Decimal:
                    return (uint) Runtime.UncheckedDecimalToInt64(ic.ToDecimal(null));

                case TypeCode.String:
                    return (uint) Runtime.DoubleToInt64(ToNumber(ic.ToString(null)));
            }
            return 0;
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:56,代码来源:Convert.cs

示例13: ToString

        internal static string ToString(object value, PreferredType pref, IConvertible ic, bool explicitOK)
        {
            Enum enum2 = value as Enum;
            if (enum2 != 0)
            {
                return enum2.ToString("G");
            }
            EnumWrapper wrapper = value as EnumWrapper;
            if (wrapper != null)
            {
                return wrapper.ToString();
            }
            TypeCode typeCode = GetTypeCode(value, ic);
            if (pref == PreferredType.LocaleString)
            {
                switch (typeCode)
                {
                    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 num = ic.ToDouble(null);
                        return num.ToString(((num <= -1E+15) || (num >= 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 (typeCode)
            {
                case TypeCode.Empty:
                    if (explicitOK)
                    {
                        return "undefined";
                    }
                    return null;

                case TypeCode.Object:
                    return ToString(ToPrimitive(value, pref, ref ic), ic);

                case TypeCode.DBNull:
                    if (explicitOK)
                    {
                        return "null";
                    }
                    return null;

                case TypeCode.Boolean:
                    if (ic.ToBoolean(null))
                    {
                        return "true";
                    }
                    return "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.Single:
                case TypeCode.Double:
                    return ToString(ic.ToDouble(null));

                case TypeCode.DateTime:
                    return ToString(DateConstructor.ob.Construct(ic.ToDateTime(null)));
            }
            return null;
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:87,代码来源:Convert.cs

示例14: ToNumber

        internal static double ToNumber(object value, IConvertible ic)
        {
            switch (GetTypeCode(value, ic))
            {
                case TypeCode.Empty:
                    return double.NaN;

                case TypeCode.Object:
                case TypeCode.DateTime:
                {
                    object obj2 = ToPrimitive(value, PreferredType.Number, ref ic);
                    if (obj2 == value)
                    {
                        return double.NaN;
                    }
                    return ToNumber(obj2, ic);
                }
                case TypeCode.DBNull:
                    return 0.0;

                case TypeCode.Boolean:
                    return (ic.ToBoolean(null) ? ((double) 1) : ((double) 0));

                case TypeCode.Char:
                    return (double) ic.ToChar(null);

                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                    return (double) ic.ToInt32(null);

                case TypeCode.UInt32:
                case TypeCode.Int64:
                    return (double) ic.ToInt64(null);

                case TypeCode.UInt64:
                    return (double) ic.ToUInt64(null);

                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                    return ic.ToDouble(null);

                case TypeCode.String:
                    return ToNumber(ic.ToString(null));
            }
            return 0.0;
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:50,代码来源:Convert.cs

示例15: JScriptStrictEquals

        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));
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:StrictEquality.cs


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