src/Elements/Generate/TypeGenerator.cs
/// <summary>
/// Generate a user-defined type in a .g.cs file from a schema.
/// </summary>
/// <param name="uri">The uri to the schema which defines the type. This can be a url or a relative file path.</param>
/// <param name="outputBaseDir">The base output directory.</param>
/// <param name="isUserElement">Is the type a user-defined element?</param>
/// <returns>
/// A GenerationResult object containing info about the success or failure of generation, 
/// the file path of the generated code, and any errors that may have occurred during generation.
/// </returns>
Generate a user-defined type in a .g.cs file from a schema.
Generate a user - defined type in a . g . cs file from a schema .
public static async Task<GenerationResult> GenerateUserElementTypeFromUriAsync(string uri, string outputBaseDir, bool isUserElement = false)
        {
            var schema = await GetSchemaAsync(uri);
            string ns;
            if (!GetNamespace(schema, out ns))
            {
                return new GenerationResult
                {
                    Success = false,
                    DiagnosticResults = new[] { "The provided schema does not contain the required 'x-namespace' property." }
                };
            }
            var typeName = schema.Title;
            var filePath = Path.Combine(outputBaseDir, GetFileNameFromTypeName(typeName));
            if (_coreTypeNames == null)
            {
                _coreTypeNames = GetCoreTypeNames();
            }
            var excludedTypeNames = _coreTypeNames.Where(n => n != typeName).ToArray();
            return WriteTypeFromSchemaToDisk(schema, filePath, typeName, ns, isUserElement, excludedTypeNames);
        }
public static async Task < GenerationResult > GenerateUserElementTypeFromUriAsync ( string uri , string outputBaseDir , bool isUserElement = false ) { var schema = await GetSchemaAsync ( uri ) ; string ns ; if ( ! GetNamespace ( schema , out ns ) ) { return new GenerationResult { Success = false , DiagnosticResults = new [ ] { " " } } ; } var typeName = schema . Title ; var filePath = Path . Combine ( outputBaseDir , GetFileNameFromTypeName ( typeName ) ) ; if ( _coreTypeNames == null ) { _coreTypeNames = GetCoreTypeNames ( ) ; } var excludedTypeNames = _coreTypeNames . Where ( n => n != typeName ) . ToArray ( ) ; return WriteTypeFromSchemaToDisk ( schema , filePath , typeName , ns , isUserElement , excludedTypeNames ) ; }
Generate a user-defined type in a .g.cs file from a schema.
Generate a user - defined type in a . g . cs file from a schema .
A GenerationResult object containing info about the success or failure of generation,
the file path of the generated code, and any errors that may have occurred during generation.
A GenerationResult object containing info about the success or failure of generation the file path of the generated code and any errors that may have occurred during generation .
uri
string
The uri to the schema which defines the type. This can be a url or a relative file path.
The uri to the schema which defines the type . This can be a url or a relative file path .
outputBaseDir
string
The base output directory.
The base output directory .
isUserElement
bool
None