public void WriteTypeSignature(TypeReference type)
        {
            if (type == null)
            {
                throw new ArgumentNullException();
            }
            ElementType etype       = type.etype;
            ElementType elementType = etype;

            if (elementType <= ElementType.GenericInst)
            {
                if (elementType == ElementType.None)
                {
                    this.WriteElementType(type.IsValueType ? ElementType.ValueType : ElementType.Class);
                    base.WriteCompressedUInt32(this.MakeTypeDefOrRefCodedRID(type));
                    return;
                }
                switch (elementType)
                {
                case ElementType.Ptr:
                case ElementType.ByRef:
                    goto IL_E3;

                case ElementType.ValueType:
                case ElementType.Class:
                    goto IL_17D;

                case ElementType.Var:
                    break;

                case ElementType.Array:
                {
                    ArrayType arrayType = (ArrayType)type;
                    if (!arrayType.IsVector)
                    {
                        this.WriteArrayTypeSignature(arrayType);
                        return;
                    }
                    this.WriteElementType(ElementType.SzArray);
                    this.WriteTypeSignature(arrayType.ElementType);
                    return;
                }

                case ElementType.GenericInst:
                {
                    GenericInstanceType genericInstanceType = (GenericInstanceType)type;
                    this.WriteElementType(ElementType.GenericInst);
                    this.WriteElementType(genericInstanceType.IsValueType ? ElementType.ValueType : ElementType.Class);
                    base.WriteCompressedUInt32(this.MakeTypeDefOrRefCodedRID(genericInstanceType.ElementType));
                    this.WriteGenericInstanceSignature(genericInstanceType);
                    return;
                }

                default:
                    goto IL_17D;
                }
            }
            else
            {
                switch (elementType)
                {
                case ElementType.FnPtr:
                {
                    FunctionPointerType method = (FunctionPointerType)type;
                    this.WriteElementType(ElementType.FnPtr);
                    this.WriteMethodSignature(method);
                    return;
                }

                case ElementType.Object:
                case ElementType.SzArray:
                    goto IL_17D;

                case ElementType.MVar:
                    break;

                case ElementType.CModReqD:
                case ElementType.CModOpt:
                {
                    IModifierType type2 = (IModifierType)type;
                    this.WriteModifierSignature(etype, type2);
                    return;
                }

                default:
                    if (elementType != ElementType.Sentinel && elementType != ElementType.Pinned)
                    {
                        goto IL_17D;
                    }
                    goto IL_E3;
                }
            }
            GenericParameter genericParameter = (GenericParameter)type;

            this.WriteElementType(etype);
            int position = genericParameter.Position;

            if (position == -1)
            {
                throw new NotSupportedException();
            }
            base.WriteCompressedUInt32((uint)position);
            return;

IL_E3:
            TypeSpecification typeSpecification = (TypeSpecification)type;

            this.WriteElementType(etype);
            this.WriteTypeSignature(typeSpecification.ElementType);
            return;

IL_17D:
            if (!this.TryWriteElementType(type))
            {
                throw new NotSupportedException();
            }
        }
Exemple #2
0
        private static void AppendTypeSpecification(TypeSpecification type, StringBuilder name)
        {
            if (type.ElementType.IsTypeSpecification())
            {
                TypeParser.AppendTypeSpecification((TypeSpecification)type.ElementType, name);
            }
            ElementType etype = type.etype;

            switch (etype)
            {
            case ElementType.Ptr:
                name.Append('*');
                return;

            case ElementType.ByRef:
                name.Append('&');
                return;

            case ElementType.ValueType:
            case ElementType.Class:
            case ElementType.Var:
                return;

            case ElementType.Array:
                break;

            case ElementType.GenericInst:
            {
                GenericInstanceType        genericInstanceType = (GenericInstanceType)type;
                Collection <TypeReference> genericArguments    = genericInstanceType.GenericArguments;
                name.Append('[');
                for (int i = 0; i < genericArguments.Count; i++)
                {
                    if (i > 0)
                    {
                        name.Append(',');
                    }
                    TypeReference typeReference = genericArguments[i];
                    bool          flag          = typeReference.Scope != typeReference.Module;
                    if (flag)
                    {
                        name.Append('[');
                    }
                    TypeParser.AppendType(typeReference, name, true, false);
                    if (flag)
                    {
                        name.Append(']');
                    }
                }
                name.Append(']');
                return;
            }

            default:
                if (etype != ElementType.SzArray)
                {
                    return;
                }
                break;
            }
            ArrayType arrayType = (ArrayType)type;

            if (arrayType.IsVector)
            {
                name.Append("[]");
                return;
            }
            name.Append('[');
            for (int j = 1; j < arrayType.Rank; j++)
            {
                name.Append(',');
            }
            name.Append(']');
        }