Ejemplo n.º 1
0
        static KeyValuePair<int, object> GetIntermediateType(Type CastType, int index, Stream stream)
        {
            int retVal = index;
            object intermediateObject = null;
            Type cTp = CastType;
            if (cTp.IsEnum)
            {
             
                
                cTp = Enum.GetUnderlyingType(cTp);
            }
            if (cTp == typeof(byte) || cTp == typeof(byte?))
            {

                if (retVal < stream.Length)
                {
                    intermediateObject = Convert.ToByte(stream.ReadByte());
                    retVal = 1;
                }
            }
            if (cTp == typeof(short) || cTp == typeof(short?))
            {

                if (retVal < stream.Length - 1)
                {
                    intermediateObject = stream.ToInt16();
                    retVal = 2;
                }
            }
            if (cTp == typeof(int) || cTp == typeof(int?))
            {

                if (retVal < stream.Length - 3)
                {

                    intermediateObject = stream.ToInt32();
                    retVal = 4;
                }
            }
            if (cTp == typeof(float) || cTp == typeof(float?))
            {

                if (retVal < stream.Length - 3)
                {

                    intermediateObject = stream.ToSingle();
                    retVal = 4;
                }
            }
            if (cTp == typeof(long) || cTp == typeof(long?))
            {

                if (retVal < stream.Length - 7)
                {

                    intermediateObject = stream.ToInt64();
                    retVal = 8;
                }
            }
            if (CastType == typeof(ArtemisString))
            {
                if (retVal < stream.Length - 3)
                {
                    ArtemisString artyString = new ArtemisString(stream, index);
                    intermediateObject = artyString;
                    retVal = artyString.Length * 2 + 4;
                }
            }
            return new KeyValuePair<int,object>(retVal, intermediateObject);
        }