Exemplo n.º 1
0
        private void SetProperties()
        {
            _jClassInfo.Properties = new List <JInfo>();
            JClassCreater classCreater = new JClassCreater();
            JArrayCreater arrayCreater = new JArrayCreater();

            List <JToken> jTokens = _jObject.Values().ToList();

            foreach (var item in jTokens)
            {
                if (item.Type.ToString().Equals(JsonType.Object))
                {
                    JClassInfo temp = classCreater.Create((JObject)item);
                    temp.Parent = _jClassInfo;
                    //temp.Type = _jClassInfo.Name + (_jClassInfo.Properties.Count(x => x.Type == "class") + 1);

                    _jClassInfo.Properties.Add(temp);
                }
                else if (item.Type.ToString().Equals(JsonType.Array))
                {
                    JArray temp = (JArray)item;
                    _jClassInfo.Properties.Add(arrayCreater.Create(temp));
                }
                else
                {
                    _jClassInfo.Properties.Add(new JValueInfo
                    {
                        Name = Converter.PathToName(item.Path),
                        Type = Converter.TypeStringConverter(item.Type.ToString())
                    });
                }
            }
        }
Exemplo n.º 2
0
        private void usc_Input_GenerateButtonClicked(object sender, Controls.GenerateButtonClickedEventArgs e)
        {
            JObject jObject;

            try
            {
                jObject = JObject.Parse(e.JsonString);
            }
            catch (Exception exception)
            {
                MessageBox.Show("json object 생성중에 예외 발생\n" + exception.Message, "알림");
                return;
            };

            JClassInfo        temp = _jClassCreater.Create(jObject);
            ClassInfoTreeNode classInfoTreeNode = new ClassInfoTreeNode(temp);

            _declareOption = e.SelectedOption;
            _formatString  = e.FormatString;

            SetNode(classInfoTreeNode);

            usc_CodeViewer.ClearTreeView();
            usc_CodeViewer.AddNode(classInfoTreeNode);
            usc_CodeViewer.SetCodeText(classInfoTreeNode.ClassCode);
        }
        public static void GenerateClassCode(JClassInfo jClassInfo, DeclareOption declareOption, string formatString)
        {
            string fieldsString = "";

            if ((declareOption & DeclareOption.CustomFormat) == DeclareOption.CustomFormat)
            {
                fieldsString = CreateMemberString(jClassInfo.Properties, formatString, declareOption);
            }
            else
            {
                StringBuilder optionalFormat = new StringBuilder();

                optionalFormat.Append(SetModifider(declareOption));
                optionalFormat.Append(" {TYPE}");
                optionalFormat.Append(" {NAME} ");

                if ((declareOption & DeclareOption.Property) == DeclareOption.Property)
                {
                    optionalFormat.Append(" {get; set;}");
                }
                else if ((declareOption & DeclareOption.NormalField) == DeclareOption.NormalField)
                {
                    optionalFormat.Append(";");
                }

                fieldsString = CreateMemberString(jClassInfo.Properties, optionalFormat.ToString(), declareOption);
            }

            string classTemplate = TemplateString.ClassTemplate;

            classTemplate = classTemplate.Replace("{FD}", fieldsString);
            classTemplate = classTemplate.Replace("{CN}", jClassInfo.Type);

            jClassInfo.ClassCode = classTemplate;
        }
Exemplo n.º 4
0
        public static void CreateClassFile(JClassInfo jClassInfo, string path, string nameSpace)
        {
            foreach (var item in jClassInfo.Properties)
            {
                if (item is JClassInfo)
                {
                    CreateClassFile((JClassInfo)item, path, nameSpace);
                }

                if (item is JArrayInfo)
                {
                    foreach (var sub in ((JArrayInfo)item).ClassTypes)
                    {
                        CreateClassFile(sub, path, nameSpace);
                    }
                }
            }

            string filePath       = $"{path}//{jClassInfo.Type}.cs";
            string templateString = TemplateString.FileTemplate;

            templateString = templateString.Replace("{CC}", jClassInfo.ClassCode);
            templateString = templateString.Replace("{NS}", nameSpace);

            File.WriteAllText(filePath, templateString);
        }
Exemplo n.º 5
0
 private void PrintJClassInfo(JClassInfo data)
 {
     Debug.Log("Effect Name: " + data.Name);
     foreach (JKeyValuePair para in data.Properties)
     {
         Debug.Log("Key = " + para.Key + " value: " + para.Value);
     }
 }
Exemplo n.º 6
0
            public override bool Equals(object obj)
            {
                JClassInfo c = obj as JClassInfo;

                if (c == null || c.Class == null || Class == null)
                {
                    return(false);
                }

                return(c.Class.Equals(Class));
            }
Exemplo n.º 7
0
        public JClassInfo Create(JObject jObject)
        {
            _jClassInfo  = new JClassInfo();
            _jObject     = jObject;
            _jProperties = _jObject.Properties().ToList();


            _jClassInfo.Name = Converter.PathToName(jObject.Path);

            _jClassInfo.Type = SharpType.Class;
            SetProperties();

            return(_jClassInfo);
        }
Exemplo n.º 8
0
        private void SetClassInfos()
        {
            var classes = (from x in _jArray.Children()
                           where x.Type.ToString() == JsonType.Object
                           select x).ToList();

            if (classes.Count == 0)
            {
                return;
            }

            JClassCreater classCreater = new JClassCreater();

            foreach (var x in classes)
            {
                JClassInfo tempInfo = classCreater.Create((JObject)x);
                tempInfo.Parent = _jArrayInfo;

                tempInfo.Type = _jArrayInfo.Name + (_jArrayInfo.ClassTypes.Count + 1);
                tempInfo.Name = "";

                if (!_jArrayInfo.ClassTypes.Contains(tempInfo))
                {
                    _jArrayInfo.ClassTypes.Add(tempInfo);
                }
            }

            if (_jArrayInfo.GenericType == SharpType.Class && _jArrayInfo.ClassTypes.Count == 1)
            {
                _jArrayInfo.GenericType = _jArrayInfo.ClassTypes[0].Type;
            }
            else
            {
                _jArrayInfo.GenericType = SharpType.Object;
            }
        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            //string json = TempStringReader.GetJsonString("../../../samplej.txt");

            //JToken jo = JToken.Parse(json);
            //Console.WriteLine(jo.Type);

            //JToken jt1 = jo[0];
            //JToken jt4 = jo[3];

            //Console.WriteLine(jt4.Count());

            //JObject jo1 = (JObject)jo[0];
            //JObject jo2 = (JObject)jo[1];
            //JObject jo3 = (JObject)jo[2];
            //JObject jo4 = (JObject)jo[3];

            //List<string> jpn1 = (from p in jo1.Properties()
            //                     select p.Name).ToList();
            //List<string> jpn2 = (from p in jo2.Properties()
            //                     select p.Name).ToList();
            //List<string> jpn3 = (from p in jo3.Properties()
            //                     select p.Name).ToList();
            //List<string> jpn4 = (from p in jo4.Properties()
            //                     select p.Name).ToList();


            //Console.WriteLine(jpn1.Intersect(jpn2).Count() == jpn1.Count);
            //Console.WriteLine(jpn1.Intersect(jpn3).Count() == jpn1.Count);

            //Console.WriteLine(jpn4.Count);

            string  str     = TempStringReader.GetJsonString("../../../samplej2.txt");
            JObject jObject = JObject.Parse(str);

            JClassCreater jCreator = new JClassCreater();

            JClassInfo jClassInfo = jCreator.Create(jObject);

            foreach (var item in jClassInfo.Properties)
            {
                Console.WriteLine(item);
            }

            Console.WriteLine();

            foreach (var property in ((JClassInfo)jClassInfo.Properties[2]).Properties)
            {
                Console.WriteLine(property);
            }

            //JArray jArray = JArray.Parse(str);
            //JArrayCreater jArrayCreater = new JArrayCreater();
            //jArrayCreater.Create(jArray);

            Console.WriteLine();

            JValueInfo v1 = new JValueInfo {
                Name = "name", Type = "string"
            };
            JValueInfo v2 = new JValueInfo {
                Name = "name", Type = "string"
            };


            Console.WriteLine(v1.Equals(v2));

            JClassInfo c1 = new JClassInfo {
                Name = "c1", Type = "class", Properties = new List <JInfo>()
            };

            c1.Properties.Add(v1);

            JClassInfo c2 = new JClassInfo {
                Name = "c1", Type = "class", Properties = new List <JInfo>()
            };

            c2.Properties.Add(v2);

            Console.WriteLine(c1.Equals(c2));
        }