/// <summary>
 ///     Static method to return generated code for a single JSON schema with no references.
 /// </summary>
 /// <param name="schema">Location of schema file.</param>
 /// <param name="ns">The namespace.</param>
 /// <param name="type">The attribute type.</param>
 /// <returns>The generated code.</returns>
 public static string Generate(string schema, string ns = "generated", AttributeType type = AttributeType.SystemDefault)
 {
     var jsonSchemaToCodeUnit = new JsonSchemaToCodeUnit(JsonSchemaResolver.ConvertToWrapper(schema), ns, type);
     CodeCompileUnit codeUnit = jsonSchemaToCodeUnit.Execute();
     var csharpGenerator = new CodeCompileUnitToCSharp(codeUnit);
     return csharpGenerator.Execute();
 }
예제 #2
0
        /// <summary>
        ///     Return a Dictionary containing a map of the generated JsonSchemaWrappers with the generated code as a string.
        /// </summary>
        /// <returns>A mapping of all the JSON schemas and the generated code.</returns>
        private Dictionary<JsonSchemaWrapper, string> GenerateHelper()
        {
            var generatedCode = new Dictionary<JsonSchemaWrapper, string>();

            foreach (JsonSchemaWrapper s in _schemas.Values)
            {
                if (s.ToCreate)
                {
                    var jsonSchemaToCodeUnit = new JsonSchemaToCodeUnit(s, s.Namespace, _configuration.AttributeType);
                    CodeCompileUnit codeUnit = jsonSchemaToCodeUnit.Execute();
                    var csharpGenerator = new CodeCompileUnitToCSharp(codeUnit);

                    generatedCode.Add(s, csharpGenerator.Execute());
                }
            }

            return generatedCode;
        }