Esempio n. 1
0
        private TypeFullDescriptor ReadFullTypeDescriptor()
        {
            TypeFullDescriptor type;
            var typeIdOrPosition = reader.ReadInt32();

            if (typeIdOrPosition == Consts.NullObjectId)
            {
                return(null);
            }

            var isGenericParameter = reader.ReadBoolean();

            if (isGenericParameter)
            {
                var genericType = ReadFullTypeDescriptor().UnderlyingType;
                type = (TypeFullDescriptor)genericType.GetGenericArguments()[typeIdOrPosition];
            }
            else
            {
                if (types.Count > typeIdOrPosition)
                {
                    type = (TypeFullDescriptor)types[typeIdOrPosition];
                }
                else
                {
                    type = new TypeFullDescriptor();
                    types.Add(type);

                    type.Read(this);
                }
            }

            if (type.UnderlyingType.IsGenericType)
            {
                var containsAnyFixedGenericArguments = reader.ReadBoolean();
                if (containsAnyFixedGenericArguments)
                {
                    var args = new Type[type.UnderlyingType.GetGenericArguments().Count()];
                    for (int i = 0; i < args.Length; i++)
                    {
                        args[i] = ReadFullTypeDescriptor().UnderlyingType;
                    }

                    type = (TypeFullDescriptor)type.UnderlyingType.MakeGenericType(args);
                }
            }

            if (Helpers.ContainsGenericArguments(type.UnderlyingType))
            {
                var ranks = reader.ReadArray();
                if (ranks.Length > 0)
                {
                    var arrayDescriptor = new ArrayDescriptor(type.UnderlyingType, ranks);
                    type = (TypeFullDescriptor)arrayDescriptor.BuildArrayType();
                }
            }

            return(type);
        }
 public FieldDescriptor(TypeFullDescriptor declaringType)
 {
     DeclaringType = declaringType;
 }