Exemple #1
0
        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());
        }
Exemple #2
0
 public virtual INestedTypeDefinition AsNestedTypeDefinition(EmitContext context) => null;
Exemple #3
0
 public virtual ITypeReference GetBaseClass(EmitContext context)
 {
     throw ExceptionUtilities.Unreachable;
 }
Exemple #4
0
 public virtual IEnumerable <ICustomAttribute> GetAttributes(EmitContext context)
 => new ICustomAttribute[0];
Exemple #5
0
 public ITypeDefinition GetResolvedType(EmitContext context) => this;
Exemple #6
0
 public IEnumerable <TypeReferenceWithAttributes> Interfaces(EmitContext context)
 => new TypeReferenceWithAttributes[0];
Exemple #7
0
 public virtual IEnumerable <INestedTypeDefinition> GetNestedTypes(EmitContext context)
 => new INestedTypeDefinition[0];
Exemple #8
0
 public IUnitReference GetUnit(EmitContext context)
 {
     Debug.Assert(context.Module == _moduleBuilder);
     return(_moduleBuilder);
 }
Exemple #9
0
 override public ITypeReference GetBaseClass(EmitContext context) => _sysValueType;
Exemple #10
0
 public override ITypeReference GetBaseClass(EmitContext context) => _systemObject;
Exemple #11
0
 public override INamespaceTypeDefinition AsNamespaceTypeDefinition(EmitContext context) => this;
Exemple #12
0
 public override IEnumerable <INestedTypeDefinition> GetNestedTypes(EmitContext context)
 {
     Debug.Assert(IsFrozen);
     return(_orderedProxyTypes.OfType <ExplicitSizeStruct>());
 }
Exemple #13
0
 public override IEnumerable <IMethodDefinition> GetMethods(EmitContext context)
 {
     Debug.Assert(IsFrozen);
     return(_orderedSynthesizedMethods);
 }
Exemple #14
0
        /// <summary>
        /// Strip off *, &amp;, 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);
            }
        }
Exemple #15
0
 public IEnumerable <MethodImplementation> GetExplicitImplementationOverrides(EmitContext context)
 => new MethodImplementation[0];
Exemple #16
0
 public override INestedTypeDefinition AsNestedTypeDefinition(EmitContext context) => this;
Exemple #17
0
 virtual public IEnumerable <IFieldDefinition> GetFields(EmitContext context)
 => new IFieldDefinition[0];
Exemple #18
0
 public MetadataConstant GetCompileTimeValue(EmitContext context) => null;
Exemple #19
0
 public virtual IEnumerable <IMethodDefinition> GetMethods(EmitContext context)
 => new IMethodDefinition[0];
Exemple #20
0
 public ITypeReference GetContainingType(EmitContext context) => _containingType;
Exemple #21
0
 public IEnumerable <IPropertyDefinition> GetProperties(EmitContext context)
 => new IPropertyDefinition[0];
Exemple #22
0
 public IDefinition AsDefinition(EmitContext context)
 {
     throw ExceptionUtilities.Unreachable;
 }
Exemple #23
0
 public IDefinition AsDefinition(EmitContext context) => this;
Exemple #24
0
 public ITypeReference GetType(EmitContext context) => _type;
Exemple #25
0
 public virtual INamespaceTypeDefinition AsNamespaceTypeDefinition(EmitContext context) => null;
Exemple #26
0
 public IFieldDefinition GetResolvedField(EmitContext context) => this;
Exemple #27
0
 public ITypeDefinition AsTypeDefinition(EmitContext context) => this;
Exemple #28
0
 public IEnumerable <IEventDefinition> GetEvents(EmitContext context)
 => new IEventDefinition[0];
Exemple #29
0
 public MetadataVisitor(EmitContext context)
 {
     this.Context = context;
 }
Exemple #30
0
        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;
                }
            }
        }