public static void WriteTo(this TypeReference type, PlainTextOutput writer, IlNameSyntax syntax = IlNameSyntax.Signature)
		{
			var syntaxForElementTypes = syntax == IlNameSyntax.SignatureNoNamedTypeParameters ? syntax : IlNameSyntax.Signature;
			if (type is PinnedType)
			{
				((PinnedType)type).ElementType.WriteTo(writer, syntaxForElementTypes);
				writer.Write(" pinned");
			}
			else if (type is ArrayType)
			{
				var at = (ArrayType)type;
				at.ElementType.WriteTo(writer, syntaxForElementTypes);
				writer.Write('[');
				writer.Write(string.Join(", ", at.Dimensions));
				writer.Write(']');
			}
			else if (type is GenericParameter)
			{
				writer.Write('!');
				if (((GenericParameter)type).Owner.GenericParameterType == GenericParameterType.Method)
					writer.Write('!');
				if (string.IsNullOrEmpty(type.Name) || type.Name[0] == '!' || syntax == IlNameSyntax.SignatureNoNamedTypeParameters)
					writer.Write(((GenericParameter)type).Position.ToString());
				else
					writer.Write(Escape(type.Name));
			}
			else if (type is ByReferenceType)
			{
				((ByReferenceType)type).ElementType.WriteTo(writer, syntaxForElementTypes);
				writer.Write('&');
			}
			else if (type is PointerType)
			{
				((PointerType)type).ElementType.WriteTo(writer, syntaxForElementTypes);
				writer.Write('*');
			}
			else if (type is GenericInstanceType)
			{
				type.GetElementType().WriteTo(writer, syntaxForElementTypes);
				writer.Write('<');
				var arguments = ((GenericInstanceType)type).GenericArguments;
				for (var i = 0; i < arguments.Count; i++)
				{
					if (i > 0)
						writer.Write(", ");
					arguments[i].WriteTo(writer, syntaxForElementTypes);
				}
				writer.Write('>');
			}
			else if (type is OptionalModifierType)
			{
				((OptionalModifierType)type).ElementType.WriteTo(writer, syntax);
				writer.Write(" modopt(");
				((OptionalModifierType)type).ModifierType.WriteTo(writer, IlNameSyntax.TypeName);
				writer.Write(") ");
			}
			else if (type is RequiredModifierType)
			{
				((RequiredModifierType)type).ElementType.WriteTo(writer, syntax);
				writer.Write(" modreq(");
				((RequiredModifierType)type).ModifierType.WriteTo(writer, IlNameSyntax.TypeName);
				writer.Write(") ");
			}
			else
			{
				var name = PrimitiveTypeName(type.FullName);
				if ((syntax == IlNameSyntax.Signature || syntax == IlNameSyntax.SignatureNoNamedTypeParameters) && name != null)
				{
					writer.Write(name);
				}
				else
				{
					if (syntax == IlNameSyntax.Signature || syntax == IlNameSyntax.SignatureNoNamedTypeParameters)
						writer.Write(type.IsValueType ? "valuetype " : "class ");
					if (type.DeclaringType != null)
					{
						type.DeclaringType.WriteTo(writer, IlNameSyntax.TypeName);
						writer.Write('/');
						writer.Write(Escape(type.Name));
					}
					else
					{
						if (!type.IsDefinition && type.Scope != null && !(type is TypeSpecification))
							writer.Write("[{0}]", Escape(type.Scope.Name));
						writer.Write(Escape(type.FullName));
					}
				}
			}
		}
        public static void WriteTo(this TypeReference type, PlainTextOutput writer, IlNameSyntax syntax = IlNameSyntax.Signature)
        {
            var syntaxForElementTypes = syntax == IlNameSyntax.SignatureNoNamedTypeParameters ? syntax : IlNameSyntax.Signature;

            if (type is PinnedType)
            {
                ((PinnedType)type).ElementType.WriteTo(writer, syntaxForElementTypes);
                writer.Write(" pinned");
            }
            else if (type is ArrayType)
            {
                var at = (ArrayType)type;
                at.ElementType.WriteTo(writer, syntaxForElementTypes);
                writer.Write('[');
                writer.Write(string.Join(", ", at.Dimensions));
                writer.Write(']');
            }
            else if (type is GenericParameter)
            {
                writer.Write('!');
                if (((GenericParameter)type).Owner.GenericParameterType == GenericParameterType.Method)
                {
                    writer.Write('!');
                }
                if (string.IsNullOrEmpty(type.Name) || type.Name[0] == '!' || syntax == IlNameSyntax.SignatureNoNamedTypeParameters)
                {
                    writer.Write(((GenericParameter)type).Position.ToString());
                }
                else
                {
                    writer.Write(Escape(type.Name));
                }
            }
            else if (type is ByReferenceType)
            {
                ((ByReferenceType)type).ElementType.WriteTo(writer, syntaxForElementTypes);
                writer.Write('&');
            }
            else if (type is PointerType)
            {
                ((PointerType)type).ElementType.WriteTo(writer, syntaxForElementTypes);
                writer.Write('*');
            }
            else if (type is GenericInstanceType)
            {
                type.GetElementType().WriteTo(writer, syntaxForElementTypes);
                writer.Write('<');
                var arguments = ((GenericInstanceType)type).GenericArguments;
                for (var i = 0; i < arguments.Count; i++)
                {
                    if (i > 0)
                    {
                        writer.Write(", ");
                    }
                    arguments[i].WriteTo(writer, syntaxForElementTypes);
                }
                writer.Write('>');
            }
            else if (type is OptionalModifierType)
            {
                ((OptionalModifierType)type).ElementType.WriteTo(writer, syntax);
                writer.Write(" modopt(");
                ((OptionalModifierType)type).ModifierType.WriteTo(writer, IlNameSyntax.TypeName);
                writer.Write(") ");
            }
            else if (type is RequiredModifierType)
            {
                ((RequiredModifierType)type).ElementType.WriteTo(writer, syntax);
                writer.Write(" modreq(");
                ((RequiredModifierType)type).ModifierType.WriteTo(writer, IlNameSyntax.TypeName);
                writer.Write(") ");
            }
            else
            {
                var name = PrimitiveTypeName(type.FullName);
                if ((syntax == IlNameSyntax.Signature || syntax == IlNameSyntax.SignatureNoNamedTypeParameters) && name != null)
                {
                    writer.Write(name);
                }
                else
                {
                    if (syntax == IlNameSyntax.Signature || syntax == IlNameSyntax.SignatureNoNamedTypeParameters)
                    {
                        writer.Write(type.IsValueType ? "valuetype " : "class ");
                    }
                    if (type.DeclaringType != null)
                    {
                        type.DeclaringType.WriteTo(writer, IlNameSyntax.TypeName);
                        writer.Write('/');
                        writer.Write(Escape(type.Name));
                    }
                    else
                    {
                        if (!type.IsDefinition && type.Scope != null && !(type is TypeSpecification))
                        {
                            writer.Write("[{0}]", Escape(type.Scope.Name));
                        }
                        writer.Write(Escape(type.FullName));
                    }
                }
            }
        }