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


C# IConvertible.ToByte方法代码示例

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


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

示例1: 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

示例2: DefaultToType

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

示例3: 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

示例4: DefaultToType

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

示例5: JScriptStrictEquals


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

示例6: DefaultToType

        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));
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:50,代码来源:convert.cs

示例7: DefaultToType

	// 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);
					}
				}
//.........这里部分代码省略.........
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:101,代码来源:Convert.cs

示例8: 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

示例9: ExecuteBinaryOperator

 private object ExecuteBinaryOperator(IConvertible left, IConvertible right, CodeBinaryOperatorType op)
 {
     TypeCode typeCode = left.GetTypeCode();
     TypeCode code2 = right.GetTypeCode();
     TypeCode[] codeArray = new TypeCode[] { TypeCode.Byte, TypeCode.Char, TypeCode.Int16, TypeCode.UInt16, TypeCode.Int32, TypeCode.UInt32, TypeCode.Int64, TypeCode.UInt64 };
     int num = -1;
     int num2 = -1;
     for (int i = 0; i < codeArray.Length; i++)
     {
         if (typeCode == codeArray[i])
         {
             num = i;
         }
         if (code2 == codeArray[i])
         {
             num2 = i;
         }
         if ((num != -1) && (num2 != -1))
         {
             break;
         }
     }
     if ((num == -1) || (num2 == -1))
     {
         return left;
     }
     int index = Math.Max(num, num2);
     object obj2 = left;
     switch (codeArray[index])
     {
         case TypeCode.Char:
         {
             char ch = left.ToChar(null);
             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;
//.........这里部分代码省略.........
开发者ID:Reegenerator,项目名称:Sample-CustomizeDatasetCS,代码行数:101,代码来源:CodeDomSerializerBase.cs

示例10: 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

示例11: InternalNegObj

        private static object InternalNegObj(object obj, IConvertible conv, TypeCode tc)
        {
            switch (tc)
            {
                case TypeCode.Empty:
                    return 0;

                case TypeCode.Boolean:
                    if (obj is bool)
                    {
                        return -((short) -(((bool) obj) > false));
                    }
                    return -((short) -(conv.ToBoolean(null) > false));

                case TypeCode.Byte:
                    if (obj is byte)
                    {
                        return (short) -((byte) obj);
                    }
                    return (short) -conv.ToByte(null);

                case TypeCode.Int16:
                    int num4;
                    if (obj is short)
                    {
                        num4 = 0 - ((short) obj);
                    }
                    else
                    {
                        num4 = 0 - conv.ToInt16(null);
                    }
                    if ((num4 >= -32768) && (num4 <= 0x7fff))
                    {
                        return (short) num4;
                    }
                    return num4;

                case TypeCode.Int32:
                    long num5;
                    if (obj is int)
                    {
                        num5 = 0L - ((int) obj);
                    }
                    else
                    {
                        num5 = 0L - conv.ToInt32(null);
                    }
                    if ((num5 >= -2147483648L) && (num5 <= 0x7fffffffL))
                    {
                        return (int) num5;
                    }
                    return num5;

                case TypeCode.Int64:
                    try
                    {
                        if (obj is long)
                        {
                            return (0L - ((long) obj));
                        }
                        return (0L - conv.ToInt64(null));
                    }
                    catch (StackOverflowException exception)
                    {
                        throw exception;
                    }
                    catch (OutOfMemoryException exception2)
                    {
                        throw exception2;
                    }
                    catch (ThreadAbortException exception3)
                    {
                        throw exception3;
                    }
                    catch (Exception)
                    {
                        return decimal.Negate(conv.ToDecimal(null));
                    }
                    break;

                case TypeCode.Single:
                    goto Label_01B9;

                case TypeCode.Double:
                    if (obj is double)
                    {
                        return -((double) obj);
                    }
                    return -conv.ToDouble(null);

                case TypeCode.Decimal:
                    break;

                case TypeCode.String:
                {
                    string str = obj as string;
                    if (str == null)
                    {
                        return -DoubleType.FromString(conv.ToString(null));
                    }
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:ObjectType.cs

示例12: AppendNumber

 /// <summary> 数字 类型对象转换Json字符串写入Buffer
 /// </summary>
 /// <param name="number">数字对象</param>
 protected virtual void AppendNumber(IConvertible number) {
     switch (number.GetTypeCode()) {
         case TypeCode.Decimal:
         case TypeCode.Double:
         case TypeCode.Single:
             Buffer.Append(number.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
             break;
         case TypeCode.Int16:
             Buffer.Append(number.ToInt16(System.Globalization.NumberFormatInfo.InvariantInfo));
             break;
         case TypeCode.Int32:
         case TypeCode.Int64:
             Buffer.Append(number.ToInt64(System.Globalization.NumberFormatInfo.InvariantInfo));
             break;
         case TypeCode.SByte:
             Buffer.Append(number.ToSByte(System.Globalization.NumberFormatInfo.InvariantInfo));
             break;
         case TypeCode.Byte:
             Buffer.Append(number.ToByte(System.Globalization.NumberFormatInfo.InvariantInfo));
             break;
         case TypeCode.UInt16:
             Buffer.Append(number.ToUInt16(System.Globalization.NumberFormatInfo.InvariantInfo));
             break;
         case TypeCode.UInt32:
         case TypeCode.UInt64:
             Buffer.Append(number.ToUInt64(System.Globalization.NumberFormatInfo.InvariantInfo));
             break;
         default:
             break;
     }
 }
开发者ID:pczy,项目名称:Pub.Class,代码行数:34,代码来源:JsonBuilder.cs


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