public override void AddCompilationRoots(IRootingServiceProvider rootProvider)
        {
            foreach (DefType type in _typesWithStructMarshalling)
            {
                rootProvider.RootStructMarshallingData(type, "Analysis based interop root");
            }

            foreach (DefType type in _typesWithDelegateMarshalling)
            {
                rootProvider.RootDelegateMarshallingData(type, "Analysis based interop root");
            }
        }
Exemple #2
0
        private void ProcessTypeDirective(IRootingServiceProvider rootProvider, ModuleDesc containingModule, XElement typeElement)
        {
            var typeNameAttribute = typeElement.Attribute("Name");

            if (typeNameAttribute == null)
            {
                throw new Exception("The \"Name\" attribute is required on the \"Type\" Runtime Directive.");
            }

            string   typeName = typeNameAttribute.Value;
            TypeDesc type     = containingModule.GetTypeByCustomAttributeTypeName(typeName);

            var dynamicDegreeAttribute = typeElement.Attribute("Dynamic");

            if (dynamicDegreeAttribute != null)
            {
                if (dynamicDegreeAttribute.Value != "Required All")
                {
                    throw new NotSupportedException($"\"{dynamicDegreeAttribute.Value}\" is not a supported value for the \"Dynamic\" attribute of the \"Type\" Runtime Directive. Supported values are \"Required All\".");
                }

                RootingHelpers.RootType(rootProvider, type, "RD.XML root");
            }

            var marshalStructureDegreeAttribute = typeElement.Attribute("MarshalStructure");

            if (marshalStructureDegreeAttribute != null && type is DefType defType)
            {
                if (marshalStructureDegreeAttribute.Value != "Required All")
                {
                    throw new NotSupportedException($"\"{marshalStructureDegreeAttribute.Value}\" is not a supported value for the \"MarshalStructure\" attribute of the \"Type\" Runtime Directive. Supported values are \"Required All\".");
                }

                rootProvider.RootStructMarshallingData(defType, "RD.XML root");
            }

            var marshalDelegateDegreeAttribute = typeElement.Attribute("MarshalDelegate");

            if (marshalDelegateDegreeAttribute != null && type.IsDelegate)
            {
                if (marshalDelegateDegreeAttribute.Value != "Required All")
                {
                    throw new NotSupportedException($"\"{marshalDelegateDegreeAttribute.Value}\" is not a supported value for the \"MarshalDelegate\" attribute of the \"Type\" Runtime Directive. Supported values are \"Required All\".");
                }

                rootProvider.RootDelegateMarshallingData((DefType)type, "RD.XML root");
            }

            foreach (var element in typeElement.Elements())
            {
                switch (element.Name.LocalName)
                {
                case "Method":
                    ProcessMethodDirective(rootProvider, containingModule, type, element);
                    break;

                default:
                    throw new NotSupportedException($"\"{element.Name.LocalName}\" is not a supported Runtime Directive.");
                }
            }
        }