示例#1
0
        /// <summary>
        /// Decomposes a constructed type into individual <see cref="TypeMetadataNode"/> units that will be needed to
        /// express the constructed type in metadata.
        /// </summary>
        public static void GetMetadataDependencies(ref DependencyList dependencies, NodeFactory nodeFactory, TypeDesc type, string reason)
        {
            MetadataManager mdManager = nodeFactory.MetadataManager;

            switch (type.Category)
            {
            case TypeFlags.Array:
            case TypeFlags.SzArray:
            case TypeFlags.ByRef:
            case TypeFlags.Pointer:
                GetMetadataDependencies(ref dependencies, nodeFactory, ((ParameterizedType)type).ParameterType, reason);
                break;

            case TypeFlags.FunctionPointer:
                var pointerType = (FunctionPointerType)type;
                GetMetadataDependencies(ref dependencies, nodeFactory, pointerType.Signature.ReturnType, reason);
                foreach (TypeDesc paramType in pointerType.Signature)
                {
                    GetMetadataDependencies(ref dependencies, nodeFactory, paramType, reason);
                }
                break;

            case TypeFlags.SignatureMethodVariable:
            case TypeFlags.SignatureTypeVariable:
                break;

            default:
                Debug.Assert(type.IsDefType);

                TypeDesc typeDefinition = type.GetTypeDefinition();
                if (typeDefinition != type)
                {
                    if (mdManager.CanGenerateMetadata((MetadataType)typeDefinition))
                    {
                        dependencies = dependencies ?? new DependencyList();
                        dependencies.Add(nodeFactory.TypeMetadata((MetadataType)typeDefinition), reason);
                    }

                    foreach (TypeDesc typeArg in type.Instantiation)
                    {
                        GetMetadataDependencies(ref dependencies, nodeFactory, typeArg, reason);
                    }
                }
                else
                {
                    if (mdManager.CanGenerateMetadata((MetadataType)type))
                    {
                        dependencies = dependencies ?? new DependencyList();
                        dependencies.Add(nodeFactory.TypeMetadata((MetadataType)type), reason);
                    }
                }
                break;
            }
        }
示例#2
0
        /// <summary>
        /// Decomposes a constructed type into individual <see cref="TypeMetadataNode"/> units that will be needed to
        /// express the constructed type in metadata.
        /// </summary>
        public static void GetMetadataDependencies(ref DependencyList dependencies, NodeFactory nodeFactory, TypeDesc type, string reason)
        {
            MetadataManager mdManager = nodeFactory.MetadataManager;

            switch (type.Category)
            {
            case TypeFlags.Array:
            case TypeFlags.SzArray:
            case TypeFlags.ByRef:
            case TypeFlags.Pointer:
                GetMetadataDependencies(ref dependencies, nodeFactory, ((ParameterizedType)type).ParameterType, reason);
                break;

            case TypeFlags.FunctionPointer:
                throw new NotImplementedException();

            default:
                Debug.Assert(type.IsDefType);

                TypeDesc typeDefinition = type.GetTypeDefinition();
                if (typeDefinition != type)
                {
                    if (mdManager.CanGenerateMetadata((MetadataType)typeDefinition))
                    {
                        dependencies = dependencies ?? new DependencyList();
                        dependencies.Add(nodeFactory.TypeMetadata((MetadataType)typeDefinition), reason);
                    }

                    foreach (TypeDesc typeArg in type.Instantiation)
                    {
                        GetMetadataDependencies(ref dependencies, nodeFactory, typeArg, reason);
                    }
                }
                else
                {
                    if (mdManager.CanGenerateMetadata((MetadataType)type))
                    {
                        dependencies = dependencies ?? new DependencyList();
                        dependencies.Add(nodeFactory.TypeMetadata((MetadataType)type), reason);
                    }
                }
                break;
            }
        }