src/Elements/Generate/TypeGenerator.cs
/// <summary>
/// Generate an in-memory assembly containing all the types generated from the supplied uris.
/// </summary>
/// <param name="uris">A collection of uris to JSON schema. These can be public urls or relative file paths.</param>
/// <returns>An assembly containing the generated types or null if no Assembly could be generated.</returns>
Generate an in-memory assembly containing all the types generated from the supplied uris.
Generate an in - memory assembly containing all the types generated from the supplied uris .
public static async Task<CompilationResult> GenerateInMemoryAssemblyFromUrisAndLoadAsync(string[] uris)
        {
            var code = new List<string>();
            foreach (var uri in uris)
            {
                try
                {
                    var schema = await GetSchemaAsync(uri);
                    string csharp = GenerateCSharpCodeForSchema(schema);
                    if (csharp == null)
                    {
                        continue;
                    }
                    code.Add(csharp);
                }
                catch (Exception ex)
                {
                    var diagnostics = new[]
                    {
                        $"There was an error reading the schema at {uri}: {ex.Message}."
                    };
                    return new CompilationResult
                    {
                        Success = false,
                        DiagnosticResults = diagnostics
                    };
                }
            }
            var compilation = GenerateCompilation(code);
            var assembly = EmitAndLoad(compilation, out string[] diagnosticResults);
            return new CompilationResult
            {
                Success = true,
                DiagnosticResults = diagnosticResults,
                Assembly = assembly
            };
        }
public static async Task < CompilationResult > GenerateInMemoryAssemblyFromUrisAndLoadAsync ( string [ ] uris ) { var code = new List < string > ( ) ; foreach ( var uri in uris ) { try { var schema = await GetSchemaAsync ( uri ) ; string csharp = GenerateCSharpCodeForSchema ( schema ) ; if ( csharp == null ) { continue ; } code . Add ( csharp ) ; } catch ( Exception ex ) { var diagnostics = new [ ] { $" There was an error reading the schema at  { uri } :  { ex . Message } . " } ; return new CompilationResult { Success = false , DiagnosticResults = diagnostics } ; } } var compilation = GenerateCompilation ( code ) ; var assembly = EmitAndLoad ( compilation , out string [ ] diagnosticResults ) ; return new CompilationResult { Success = true , DiagnosticResults = diagnosticResults , Assembly = assembly } ; }
Generate an in-memory assembly containing all the types generated from the supplied uris.
Generate an in - memory assembly containing all the types generated from the supplied uris .
// https://docs.microsoft.com/en-us/archive/msdn-magazine/2017/may/net-core-cross-platform-code-generation-with-roslyn-and-net-core
An assembly containing the generated types or null if no Assembly could be generated.
An assembly containing the generated types or null if no Assembly could be generated .
uris
string[]
A collection of uris to JSON schema. These can be public urls or relative file paths.
A collection of uris to JSON schema . These can be public urls or relative file paths .