//-------------------------------------------------------------------------------------------------------------------------------------------------

            public CompilationResult Compile(ICollection <TypeMember> types)
            {
                _expectedCompile.Should().NotBeNull("Unexpected call to backend Compile()");
                _expectedCompile.Should().BeEquivalentTo(types, "Unexpected types in call to backend Compile()");
                _expectedCompile = null;

                var succeeded = new List <TypeCompilationResult>();
                var failed    = new List <TypeCompilationResult>();
                var products  = new List <TypeFactoryProduct <TestArtifact> >();
                var index     = 0;

                foreach (var type in types.Where(t => t.Generator.TypeKey.HasValue))
                {
                    if (_expectedSuccess[index++])
                    {
                        var artifact = new TestArtifact(type);
                        succeeded.Add(new TypeCompilationResult <TestArtifact>(type, true, artifact, new CompilationDiagnostic[0]));
                        products.Add(new TypeFactoryProduct <TestArtifact>(type.Generator.TypeKey.Value, artifact));
                    }
                    else
                    {
                        failed.Add(new TypeCompilationResult <TestArtifact>(type, false, null, new[] {
                            new CompilationDiagnostic(CompilationDiagnosticSeverity.Error, "ERRTEST01", "Test error", "source.cs(1,1)")
                        }));
                    }
                }

                if (products.Count > 0)
                {
                    ProductsLoaded?.Invoke(products.ToArray());
                }

                return(new CompilationResult(succeeded, failed, new List <CompilationDiagnostic>()));
            }
Exemple #2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public void LoadPrecompiledAssembly(string filePath)
        {
            var name     = new AssemblyName(Path.GetFileNameWithoutExtension(filePath));
            var assembly = Assembly.Load(name);

            _compiledAssemblies.Add(assembly);

            var artifactPerTypeKey = LoadProductAssembly(assembly);
            var loadedProducts     = artifactPerTypeKey
                                     .Select(keyArtifactPair => new TypeFactoryProduct <IRuntimeTypeFactoryArtifact>(
                                                 keyArtifactPair.Key,
                                                 keyArtifactPair.Value))
                                     .ToArray();

            ProductsLoaded?.Invoke(loadedProducts);
        }
Exemple #3
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public CompilationResult Compile(ICollection <TypeMember> types)
        {
            using (TypeMemberTagCache.CreateOnCurrentThread())
            {
                var syntaxTree = GenerateSyntaxTree(types, out Assembly[] referencedAssemblies);
                var success    = TryCompileNewAssembly(
                    referencedAssemblies,
                    ref syntaxTree,
                    out Assembly assembly,
                    out ImmutableArray <Diagnostic> diagnostics);

                if (success)
                {
                    var artifactPerTypeKey = LoadProductAssembly(assembly);
                    var productPerType     = CreateProductPerTypeDictionary(types, artifactPerTypeKey);

                    ProductsLoaded?.Invoke(productPerType.Values.ToArray());

                    return(CreateSuccessfulCompilationResult(types, diagnostics, productPerType));
                }

                return(CreateFailedCompilatioResult(types, diagnostics, syntaxTree));
            }
        }
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            public void RaiseProductsLoaded(params TypeFactoryProduct <TestArtifact>[] products)
            {
                ProductsLoaded?.Invoke(products);
            }