예제 #1
0
        // Returns true if we need to look at the children, false otherwise.
        private bool VisitTypeReference(ITypeReference typeReference)
        {
            if (!_alreadySeen.Add(typeReference))
            {
                if (!this.typeReferenceNeedsToken)
                {
                    return(false);
                }

                this.typeReferenceNeedsToken = false;
                if (!_alreadyHasToken.Add(typeReference))
                {
                    return(false);
                }

                RecordTypeReference(typeReference);

                return(false);
            }

            INestedTypeReference /*?*/ nestedTypeReference = typeReference.AsNestedTypeReference;

            if (this.typeReferenceNeedsToken || nestedTypeReference != null ||
                (typeReference.TypeCode == PrimitiveTypeCode.NotPrimitive && typeReference.AsNamespaceTypeReference != null))
            {
                ISpecializedNestedTypeReference /*?*/ specializedNestedTypeReference = nestedTypeReference?.AsSpecializedNestedTypeReference;
                if (specializedNestedTypeReference != null)
                {
                    INestedTypeReference unspecializedNestedTypeReference = specializedNestedTypeReference.GetUnspecializedVersion(Context);
                    if (_alreadyHasToken.Add(unspecializedNestedTypeReference))
                    {
                        RecordTypeReference(unspecializedNestedTypeReference);
                    }
                }

                if (this.typeReferenceNeedsToken && _alreadyHasToken.Add(typeReference))
                {
                    RecordTypeReference(typeReference);
                }

                if (nestedTypeReference != null)
                {
                    this.typeReferenceNeedsToken = (typeReference.AsSpecializedNestedTypeReference == null);
                    this.Visit(nestedTypeReference.GetContainingType(Context));
                }
            }

            //This code was in CCI, but appears wrong to me. There is no need to visit attributes of types that are
            //being referenced, only those being defined. This code causes additional spurious typerefs and memberrefs to be
            //emitted. If the attributes can't be resolved, it causes a NullReference.
            //
            //if ((typeReference.AsTypeDefinition(Context) == null))
            //{
            //    this.Visit(typeReference.GetAttributes(Context));
            //}

            this.typeReferenceNeedsToken = false;
            return(true);
        }
        internal static ITypeReference GetUninstantiatedGenericType(this ITypeReference typeReference, EmitContext context)
        {
            IGenericTypeInstanceReference genericTypeInstanceReference = typeReference.AsGenericTypeInstanceReference;

            if (genericTypeInstanceReference != null)
            {
                return(genericTypeInstanceReference.GetGenericType(context));
            }

            ISpecializedNestedTypeReference specializedNestedType = typeReference.AsSpecializedNestedTypeReference;

            if (specializedNestedType != null)
            {
                return(specializedNestedType.GetUnspecializedVersion(context));
            }

            return(typeReference);
        }