public static AssemblyLoaderInfo LoadAssemblyLoader(
            bool createTemporaryAssemblies, bool hasUnmanaged, ref CSharpCompilation compilation, CSharpParseOptions parseOptions)
        {
            compilation = compilation.AddSyntaxTrees(SyntaxFactory.ParseSyntaxTree(Resources.Common, parseOptions));

            AssemblyLoaderInfo info = new AssemblyLoaderInfo();
            string             sourceTypeCode;

            if (createTemporaryAssemblies)
            {
                sourceTypeCode      = Resources.TemplateWithTempAssembly;
                info.SourceTypeName = "TemplateWithTempAssembly";
            }
            else if (hasUnmanaged)
            {
                sourceTypeCode      = Resources.TemplateWithUnmanagedHandler;
                info.SourceTypeName = "TemplateWithUnmanagedHandler";
            }
            else
            {
                sourceTypeCode      = Resources.Template;
                info.SourceTypeName = "Template";
            }

            info.SourceType = SyntaxFactory.ParseCompilationUnit(sourceTypeCode /*, options: parseOptions*/);

            info.AssemblyNamesField = "assemblyNames";
            info.SymbolNamesField   = "symbolNames";
            info.PreloadListField   = "preloadList";
            info.Preload32ListField = "preload32List";
            info.Preload64ListField = "preload64List";
            info.ChecksumsField     = Optional("checksums");
            info.Md5HashField       = Optional("md5Hash");
            return(info);

            string Optional(string field) =>
            info.SourceType.DescendantNodes().OfType <FieldDeclarationSyntax>()
            .SelectMany(f => f.Declaration.Variables)
            .Any(f => f.Identifier.ValueText == field)
                    ? field : null;
        }
示例#2
0
        public void SynthesizeCallToAttach(ref CSharpCompilation compilation, CSharpParseOptions parseOptions, AssemblyLoaderInfo assemblyLoaderInfo)
        {
            string code = Resources.ModuleInitializer.Replace("TEMPLATE", assemblyLoaderInfo.SourceTypeName);

            compilation = compilation.AddSyntaxTrees(SyntaxFactory.ParseSyntaxTree(code, parseOptions));
        }
 public ResourceNameFinder(AssemblyLoaderInfo info, IEnumerable <string> resourceNames)
 {
     this.info          = info;
     this.resourceNames = resourceNames;
 }