Пример #1
0
        internal void FinalizeDefiniton()
        {
            var genericParameters = GenericTypeDefinition.GenericParameters;

            if (GenericTypeDefinition.BaseType != null)
            {
                BaseType = (DeclaringTypeData)GenericTypeDefinition.BaseType.ReplaceGenericTypeParameters(genericParameters, GenericArguments);
            }

            ImplementedInterfaces = new ImplementedInterfacesCollection(
                GenericTypeDefinition.ImplementedInterfaces.Select(i => (DeclaringTypeData)i.ReplaceGenericTypeParameters(genericParameters, GenericArguments))
                );

            if (TypeKind == Microsoft.CodeAnalysis.TypeKind.Delegate)
            {
                var invokeMethod = (MethodData)GenericTypeDefinition.GetMethod("Invoke").ReplaceGenericTypeParameters(genericParameters, GenericArguments);
                DelegateParameters          = invokeMethod.Parameters;
                DelegateReturnType          = invokeMethod.Type;
                DelegateReturnTypeIsDynamic = invokeMethod.IsTypeDynamic;
            }
            else
            {
                foreach (var member in GenericTypeDefinition.GetMembers().Where(m => m.MetadataItemKind != MetadataItemKinds.TypeDefinition))
                {
                    AddMember(member.ReplaceGenericTypeParameters(genericParameters, GenericArguments));
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Populates the type with additional information which can't be loaded when the type is created (due to potential circularities in item dependencies).
        /// </summary>
        /// <param name="underlyingTypeSymbol">The underlying type this instance represents.</param>
        internal void FinalizeDefinition(INamedTypeSymbol underlyingTypeSymbol)
        {
            if (underlyingTypeSymbol.TypeKind == TypeKind.Enum)
            {
                BaseType = (DeclaringTypeData)Context.GetTypeData(underlyingTypeSymbol.EnumUnderlyingType);
            }
            else if (underlyingTypeSymbol.BaseType != null)
            {
                BaseType = (DeclaringTypeData)Context.GetTypeData(underlyingTypeSymbol.BaseType);
            }

            ImplementedInterfaces = new ImplementedInterfacesCollection(
                underlyingTypeSymbol.Interfaces.Select(i => (DeclaringTypeData)Context.GetTypeData(i)).Where(i => i != null)
                );

            if (TypeKind == TypeKind.Delegate)
            {
                var invokeMethod = underlyingTypeSymbol.Methods().Single(m => m.Name == "Invoke");
                DelegateParameters          = new ParameterCollection(invokeMethod.Parameters, this);
                DelegateReturnType          = Context.GetTypeData(invokeMethod.ReturnType);
                DelegateReturnTypeIsDynamic = invokeMethod.IsReturnTypeDynamic();
            }

            if (!underlyingTypeSymbol.TypeParameters.IsEmpty)
            {
                GenericParameters = Utilities.GetGenericParameters(underlyingTypeSymbol, this);
                Debug.Assert(
                    _constructedGenericTypes == null || _constructedGenericTypes.Values.All(c => c.GenericArguments.Count == GenericParameters.Count),
                    "The type arity does not match.");
            }
            else
            {
                GenericParameters = GenericTypeParameterData.EmptyList;
                Debug.Assert(_constructedGenericTypes == null, "There should be no constructed generic types.");
            }

            NameForComparison = GetDisplayName(fullyQualify: true, includeGenericInfo: false);

            Debug.Assert(_constructedGenericTypes == null || _constructedGenericTypes.Keys.All(t => t.Count == GenericParameters.Count), "A constructed generic has the wrong type arity.");
        }