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