Exemplo n.º 1
0
        private void PrintType(ITypeSignature typeSig, IModule module, bool ignoreOwner)
        {
            switch (typeSig.ElementCode)
            {
            case TypeElementCode.Array:
            {
                PrintType(typeSig.ElementType, module, ignoreOwner);
                PrintArrayDimensions(typeSig.ArrayDimensions);
            }
            break;

            case TypeElementCode.ByRef:
            {
                PrintType(typeSig.ElementType, module, ignoreOwner);
                _builder.Append("&");
            }
            break;

            case TypeElementCode.CustomModifier:
            {
                PrintType(typeSig.ElementType, module, ignoreOwner);

                CustomModifierType modifierType;
                var modifier = typeSig.GetCustomModifier(out modifierType);
                if (modifier != null)
                {
                    if (modifierType == CustomModifierType.ModOpt)
                    {
                        _builder.Append(" modopt(");
                    }
                    else
                    {
                        _builder.Append(" modreq(");
                    }

                    PrintType(modifier, module, false);

                    _builder.Append(")");
                }
            }
            break;

            case TypeElementCode.FunctionPointer:
            {
                var callSite = typeSig.GetFunctionPointer();
                if (callSite.IsStatic)
                {
                    _builder.Append("static ");
                }

                PrintMethodCallConv(callSite.CallConv);
                _builder.Append("*");
                PrintMethodArguments(callSite.Arguments, callSite.VarArgIndex, module);
                _builder.Append(" : ");
                PrintType(callSite.ReturnType, module, false);
            }
            break;

            case TypeElementCode.GenericParameter:
            {
                bool isMethod;
                int  position;
                typeSig.GetGenericParameter(out isMethod, out position);

                if (isMethod)
                {
                    _builder.Append("!!");
                }
                else
                {
                    _builder.Append("!");
                }

                _builder.Append(position);
            }
            break;

            case TypeElementCode.GenericType:
            {
                PrintDeclaringType(typeSig.DeclaringType, module, ignoreOwner);
                PrintGenericArguments(typeSig.GenericArguments, module);
            }
            break;

            case TypeElementCode.Pinned:
            {
                PrintType(typeSig.ElementType, module, ignoreOwner);
                _builder.Append(" pinned");
            }
            break;

            case TypeElementCode.Pointer:
            {
                PrintType(typeSig.ElementType, module, ignoreOwner);
                _builder.Append("*");
            }
            break;

            case TypeElementCode.DeclaringType:
            {
                if ((_flags & SignaturePrintingFlags.UsePrimitiveTypes) == SignaturePrintingFlags.UsePrimitiveTypes)
                {
                    var typeCode = typeSig.GetTypeCode(module);
                    if (typeCode != PrimitiveTypeCode.Undefined)
                    {
                        _builder.Append(PrimitiveTypeNames[(int)typeCode]);
                        return;
                    }
                }

                PrintDeclaringType(typeSig, module, ignoreOwner);
            }
            break;

            default:
                throw new InvalidOperationException();
            }
        }