示例#1
0
        private void ProcessMethodDirective(IRootingServiceProvider rootProvider, ModuleDesc containingModule, TypeDesc containingType, XElement methodElement)
        {
            var methodNameAttribute = methodElement.Attribute("Name");
            if (methodNameAttribute == null)
                throw new Exception();
            string methodName = methodNameAttribute.Value;
            MethodDesc method = containingType.GetMethod(methodName, null);

            var instArgs = new List<TypeDesc>();
            foreach (var element in methodElement.Elements())
            {
                switch (element.Name.LocalName)
                {
                    case "GenericArgument":
                        string instArgName = element.Attribute("Name").Value;
                        instArgs.Add(containingModule.GetTypeByCustomAttributeTypeName(instArgName));
                        break;
                    default:
                        throw new NotSupportedException();
                }
            }

            if (instArgs.Count != method.Instantiation.Length)
                throw new Exception();

            if (instArgs.Count > 0)
            {
                var methodInst = new Instantiation(instArgs.ToArray());
                method = method.MakeInstantiatedMethod(methodInst);
            }

            RootingHelpers.TryRootMethod(rootProvider, method, "RD.XML root");
        }
示例#2
0
        public override void GetDependenciesDueToLdToken(ref DependencyList dependencies, NodeFactory factory, MethodDesc method)
        {
            // In order for the RuntimeMethodHandle data structure to be usable at runtime, ensure the method
            // is generating metadata.
            if ((GetMetadataCategory(method) & MetadataCategory.Description) == MetadataCategory.Description)
            {
                dependencies = dependencies ?? new DependencyList();
                dependencies.Add(factory.MethodMetadata(method.GetTypicalMethodDefinition()), "LDTOKEN method");
            }

            // Since this is typically used for LINQ expressions, let's also make sure there's runnable code
            // for this available, unless this is ldtoken of something we can't generate code for
            // (ldtoken of an uninstantiated generic method - F# makes this).
            if (!method.IsGenericMethodDefinition)
            {
                var deps = dependencies ?? new DependencyList();
                RootingHelpers.TryRootMethod(
                    new RootingServiceProvider(
                        factory, (o, reason) => deps.Add((DependencyNodeCore <NodeFactory>)o, reason)), method, "LDTOKEN method");
                dependencies = deps;
            }
        }