Example #1
0
        // TODO: write a generic method for each Primitive type, in order to avoid boxing to object.
        internal static Object TranscodeStringToPrimitiveObject(string s, L3TypeManager typeManager)
        {
            TypeCode tc = (TypeCode)typeManager.TypeIndex;

#if DEBUG
            if ((int)tc < (int)TypeCode.Boolean)
            {
                throw new ArgumentException(ErrorMessages.GetText(9));                //"data is not a Primitive type");
            }
#endif
            switch (tc)
            {
            case TypeCode.Boolean:
                return(Boolean.Parse(s));

            case TypeCode.Byte:
                return(Byte.Parse(s));

            case TypeCode.Char:
#if SILVERLIGHT || PORTABLE
                return(s[0]);
#else
                return(Char.Parse(s));
#endif
            case TypeCode.DateTime:
                return(Tools.DateTimeFromTicksAndKind(ulong.Parse(s)));

            case TypeCode.Decimal:
                return(Decimal.Parse(s, Tools.EnUSCulture));

            case TypeCode.Double:
                return(Double.Parse(s, Tools.EnUSCulture));

            case TypeCode.Int16:
                return(Int16.Parse(s));

            case TypeCode.Int32:
                return(Int32.Parse(s));

            case TypeCode.Int64:
                return(Int64.Parse(s));

            case TypeCode.SByte:
                return(SByte.Parse(s));

            case TypeCode.Single:
                return(Single.Parse(s, Tools.EnUSCulture));

            case TypeCode.String:
                return(s);

            case TypeCode.UInt16:
                return(UInt16.Parse(s));

            case TypeCode.UInt32:
                return(UInt32.Parse(s));

            case TypeCode.UInt64:
                return(UInt64.Parse(s));

            default:
                throw new Exception();
            }
        }
Example #2
0
 internal NoMethodsException(Type t)
     : base(string.Format(
                ErrorMessages.GetText(13)         // "Type {0} has no Add() method nor [Insert() method and Count get method], we can not set its items."
                , t.FullName))
 {
 }
Example #3
0
        // TODO: write a generic method for each Primitive type, in order to avoid boxing to object.
        internal Object ReadPrimitiveObjectFromBinaryStream(BinaryReader2 binaryReader, L3TypeManager typeManager, bool CompressIntsAs7Bits)
        {
            TypeCode tc = (TypeCode)typeManager.TypeIndex;

#if DEBUG
            if ((int)tc < (int)TypeCode.Boolean)
            {
                throw new ArgumentException(ErrorMessages.GetText(9));                //"data is not a Primitive type");
            }
#endif
            switch (tc)
            {
            case TypeCode.Boolean:
                return(binaryReader.ReadBoolean());

            case TypeCode.Byte:
                return(binaryReader.ReadByte());

            case TypeCode.Char:
                return(binaryReader.ReadChar());

            case TypeCode.DateTime:
                return(Tools.DateTimeFromTicksAndKind(binaryReader.ReadUInt64()));

            case TypeCode.Decimal:
                return(binaryReader.ReadDecimal());

            case TypeCode.Double:
                return(binaryReader.ReadDouble());

            case TypeCode.SByte:
                return(binaryReader.ReadSByte());

            case TypeCode.Single:
                return(binaryReader.ReadSingle());

            case TypeCode.String:
                return(binaryReader.ReadString());

            case TypeCode.Int16:
                if (CompressIntsAs7Bits)
                {
                    return(binaryReader.ReadSpecial7BitEncodedShort());
                }
                else
                {
                    return(binaryReader.ReadInt16());
                }

            case TypeCode.Int32:
                if (CompressIntsAs7Bits)
                {
                    return(binaryReader.ReadSpecial7BitEncodedInt());
                }
                else
                {
                    return(binaryReader.ReadInt32());
                }

            case TypeCode.Int64:
                if (CompressIntsAs7Bits)
                {
                    return(binaryReader.ReadSpecial7BitEncodedLong());
                }
                else
                {
                    return(binaryReader.ReadInt64());
                }

            case TypeCode.UInt16:
                if (CompressIntsAs7Bits)
                {
                    return(binaryReader.Read7BitEncodedUShort());
                }
                else
                {
                    return(binaryReader.ReadUInt16());
                }

            case TypeCode.UInt32:
                if (CompressIntsAs7Bits)
                {
                    return(binaryReader.Read7BitEncodedUInt());
                }
                else
                {
                    return(binaryReader.ReadUInt32());
                }

            case TypeCode.UInt64:
                if (CompressIntsAs7Bits)
                {
                    return(binaryReader.Read7BitEncodedULong());
                }
                else
                {
                    return(binaryReader.ReadUInt64());
                }

            default:
#if DEBUG
                throw new Exception();
#else
                return(null);
#endif
            }
        }