internal static string GetSerializedTypeName(this ITypeReference typeReference, EmitContext context, ref bool isAssemblyQualified) { var pooled = PooledStringBuilder.GetInstance(); StringBuilder sb = pooled.Builder; IArrayTypeReference arrType = typeReference as IArrayTypeReference; if (arrType != null) { typeReference = arrType.GetElementType(context); bool isAssemQual = false; AppendSerializedTypeName(sb, typeReference, ref isAssemQual, context); if (arrType.IsSZArray) { sb.Append("[]"); } else { sb.Append('['); if (arrType.Rank == 1) { sb.Append('*'); } sb.Append(',', (int)arrType.Rank - 1); sb.Append(']'); } goto done; } IPointerTypeReference pointer = typeReference as IPointerTypeReference; if (pointer != null) { typeReference = pointer.GetTargetType(context); bool isAssemQual = false; AppendSerializedTypeName(sb, typeReference, ref isAssemQual, context); sb.Append('*'); goto done; } INamespaceTypeReference namespaceType = typeReference.AsNamespaceTypeReference; if (namespaceType != null) { var name = namespaceType.NamespaceName; if (name.Length != 0) { sb.Append(name); sb.Append('.'); } sb.Append(GetMangledAndEscapedName(namespaceType)); goto done; } if (typeReference.IsTypeSpecification()) { ITypeReference uninstantiatedTypeReference = typeReference.GetUninstantiatedGenericType(context); List <ITypeReference> consolidatedTypeArguments = new List <ITypeReference>(); typeReference.GetConsolidatedTypeArguments(consolidatedTypeArguments, context); bool uninstantiatedTypeIsAssemblyQualified = false; sb.Append(GetSerializedTypeName(uninstantiatedTypeReference, context, ref uninstantiatedTypeIsAssemblyQualified)); sb.Append('['); bool first = true; foreach (ITypeReference argument in consolidatedTypeArguments) { if (first) { first = false; } else { sb.Append(','); } bool isAssemQual = true; AppendSerializedTypeName(sb, argument, ref isAssemQual, context); } sb.Append(']'); goto done; } INestedTypeReference nestedType = typeReference.AsNestedTypeReference; if (nestedType != null) { bool nestedTypeIsAssemblyQualified = false; sb.Append(GetSerializedTypeName(nestedType.GetContainingType(context), context, ref nestedTypeIsAssemblyQualified)); sb.Append('+'); sb.Append(GetMangledAndEscapedName(nestedType)); goto done; } // TODO: error done: if (isAssemblyQualified) { AppendAssemblyQualifierIfNecessary(sb, UnwrapTypeReference(typeReference, context), out isAssemblyQualified, context); } return(pooled.ToStringAndFree()); }
public virtual INestedTypeDefinition AsNestedTypeDefinition(EmitContext context) => null;
public virtual ITypeReference GetBaseClass(EmitContext context) { throw ExceptionUtilities.Unreachable; }
public virtual IEnumerable <ICustomAttribute> GetAttributes(EmitContext context) => new ICustomAttribute[0];
public ITypeDefinition GetResolvedType(EmitContext context) => this;
public IEnumerable <TypeReferenceWithAttributes> Interfaces(EmitContext context) => new TypeReferenceWithAttributes[0];
public virtual IEnumerable <INestedTypeDefinition> GetNestedTypes(EmitContext context) => new INestedTypeDefinition[0];
public IUnitReference GetUnit(EmitContext context) { Debug.Assert(context.Module == _moduleBuilder); return(_moduleBuilder); }
override public ITypeReference GetBaseClass(EmitContext context) => _sysValueType;
public override ITypeReference GetBaseClass(EmitContext context) => _systemObject;
public override INamespaceTypeDefinition AsNamespaceTypeDefinition(EmitContext context) => this;
public override IEnumerable <INestedTypeDefinition> GetNestedTypes(EmitContext context) { Debug.Assert(IsFrozen); return(_orderedProxyTypes.OfType <ExplicitSizeStruct>()); }
public override IEnumerable <IMethodDefinition> GetMethods(EmitContext context) { Debug.Assert(IsFrozen); return(_orderedSynthesizedMethods); }
/// <summary> /// Strip off *, &, and []. /// </summary> private static ITypeReference UnwrapTypeReference(ITypeReference typeReference, EmitContext context) { while (true) { IArrayTypeReference arrType = typeReference as IArrayTypeReference; if (arrType != null) { typeReference = arrType.GetElementType(context); continue; } IPointerTypeReference pointer = typeReference as IPointerTypeReference; if (pointer != null) { typeReference = pointer.GetTargetType(context); continue; } return(typeReference); } }
public IEnumerable <MethodImplementation> GetExplicitImplementationOverrides(EmitContext context) => new MethodImplementation[0];
public override INestedTypeDefinition AsNestedTypeDefinition(EmitContext context) => this;
virtual public IEnumerable <IFieldDefinition> GetFields(EmitContext context) => new IFieldDefinition[0];
public MetadataConstant GetCompileTimeValue(EmitContext context) => null;
public virtual IEnumerable <IMethodDefinition> GetMethods(EmitContext context) => new IMethodDefinition[0];
public ITypeReference GetContainingType(EmitContext context) => _containingType;
public IEnumerable <IPropertyDefinition> GetProperties(EmitContext context) => new IPropertyDefinition[0];
public IDefinition AsDefinition(EmitContext context) { throw ExceptionUtilities.Unreachable; }
public IDefinition AsDefinition(EmitContext context) => this;
public ITypeReference GetType(EmitContext context) => _type;
public virtual INamespaceTypeDefinition AsNamespaceTypeDefinition(EmitContext context) => null;
public IFieldDefinition GetResolvedField(EmitContext context) => this;
public ITypeDefinition AsTypeDefinition(EmitContext context) => this;
public IEnumerable <IEventDefinition> GetEvents(EmitContext context) => new IEventDefinition[0];
public MetadataVisitor(EmitContext context) { this.Context = context; }
private static void AppendAssemblyQualifierIfNecessary(StringBuilder sb, ITypeReference typeReference, out bool isAssemQualified, EmitContext context) { INestedTypeReference nestedType = typeReference.AsNestedTypeReference; if (nestedType != null) { AppendAssemblyQualifierIfNecessary(sb, nestedType.GetContainingType(context), out isAssemQualified, context); return; } IGenericTypeInstanceReference genInst = typeReference.AsGenericTypeInstanceReference; if (genInst != null) { AppendAssemblyQualifierIfNecessary(sb, genInst.GetGenericType(context), out isAssemQualified, context); return; } IArrayTypeReference arrType = typeReference as IArrayTypeReference; if (arrType != null) { AppendAssemblyQualifierIfNecessary(sb, arrType.GetElementType(context), out isAssemQualified, context); return; } IPointerTypeReference pointer = typeReference as IPointerTypeReference; if (pointer != null) { AppendAssemblyQualifierIfNecessary(sb, pointer.GetTargetType(context), out isAssemQualified, context); return; } isAssemQualified = false; IAssemblyReference referencedAssembly = null; INamespaceTypeReference namespaceType = typeReference.AsNamespaceTypeReference; if (namespaceType != null) { referencedAssembly = namespaceType.GetUnit(context) as IAssemblyReference; } if (referencedAssembly != null) { var containingAssembly = context.Module.GetContainingAssembly(context); if (containingAssembly == null || !ReferenceEquals(referencedAssembly, containingAssembly)) { sb.Append(", "); sb.Append(MetadataWriter.StrongName(referencedAssembly)); isAssemQualified = true; } } }