示例#1
0
        /// <summary>
        /// Create the code file specified in the data model object.
        /// </summary>
        /// <param name="fileName">The full path where the file is to be created.</param>
        /// <param name="stream">The JSON data.</param>
        /// <param name="data">The data model container.</param>
        public static void CreateFile(string fileName, StreamReader stream, JsonModelContainer data)
        {
            // Make sure the page reference exists.
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            JsonModel       model = new JsonModel();
            CodeCompileUnit code  = model.Generate(stream, data);

            model.CreateCodeFile(fileName, code);
        }
示例#2
0
        /// <summary>
        /// Map all the json data into classes, properties and references.
        /// </summary>
        /// <param name="stream">The JSON data.</param>
        /// <param name="data">The data model container.</param>
        /// <returns>The json document.</returns>
        public static JsonDocument ClassMapper(StreamReader stream, JsonModelContainer data)
        {
            // Make sure the page reference exists.
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            Json.JsonGenerator jsonGenerator = new JsonGenerator(stream);
            jsonGenerator.Namespace     = data.Namespace;
            jsonGenerator.RootClassName = data.RootClassName;
            JsonClass[] classess = GetClasses(jsonGenerator);
            return(new JsonDocument()
            {
                Namespace = data.Namespace,
                RootClassName = data.RootClassName,
                JsonClasses = classess
            });
        }
示例#3
0
        /// <summary>
        /// Generate the code.
        /// </summary>
        /// <param name="json">The JSON data.</param>
        /// <param name="data">The JSON model container.</param>
        /// <returns>The code unit.</returns>
        public CodeCompileUnit Generate(string json, JsonModelContainer data)
        {
            // Make sure the page reference exists.
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            if (json == null)
            {
                throw new ArgumentNullException("json");
            }

            // If not null.
            if (data != null)
            {
                _nameSpace     = data.Namespace;
                _rootClassName = data.RootClassName;

                Json.JsonGenerator jsonGenerator = new JsonGenerator(json);
                jsonGenerator.Namespace     = _nameSpace;
                jsonGenerator.RootClassName = _rootClassName;
                _typeList = jsonGenerator.Extract();

                // Create the namespace.
                InitialiseNamespace();
            }

            // If not null.
            if (data != null)
            {
                _data = data;
                AddClasses();
            }

            // Return the complie unit.
            _targetUnit.Namespaces.Add(_samples);
            return(_targetUnit);
        }