Exemplo n.º 1
0
        private static object decode_cattr_value(Type t, byte[] data, int pos, out int rpos)
        {
            TypeCode typeCode = Type.GetTypeCode(t);

            switch (typeCode)
            {
            case TypeCode.Object:
            {
                int num = (int)data[pos];
                pos++;
                if (num >= 2 && num <= 14)
                {
                    return(CustomAttributeBuilder.decode_cattr_value(CustomAttributeBuilder.elementTypeToType(num), data, pos, out rpos));
                }
                throw new Exception("Subtype '" + num + "' of type object not yet handled in decode_cattr_value");
            }

            default:
            {
                if (typeCode == TypeCode.Int32)
                {
                    rpos = pos + 4;
                    return((int)data[pos] + ((int)data[pos + 1] << 8) + ((int)data[pos + 2] << 16) + ((int)data[pos + 3] << 24));
                }
                if (typeCode != TypeCode.String)
                {
                    throw new Exception("FIXME: Type " + t + " not yet handled in decode_cattr_value.");
                }
                if (data[pos] == 255)
                {
                    rpos = pos + 1;
                    return(null);
                }
                int num2 = CustomAttributeBuilder.decode_len(data, pos, out pos);
                rpos = pos + num2;
                return(CustomAttributeBuilder.string_from_bytes(data, pos, num2));
            }

            case TypeCode.Boolean:
                rpos = pos + 1;
                return(data[pos] != 0);
            }
        }