From 5c7a7df9e2c122ef9d3255252a254fb543b2a350 Mon Sep 17 00:00:00 2001 From: "adis.kovacevic" Date: Thu, 18 May 2017 12:08:44 -0500 Subject: [PATCH 1/4] Added Namespace Textbox --- .vs/config/applicationhost.config | 1020 +++++++++++++++++++++++ JsonUtils/Controllers/HomeController.cs | 10 +- JsonUtils/ViewModels/IndexViewModel.cs | 2 + JsonUtils/Views/Home/Index.cshtml | 31 +- 4 files changed, 1055 insertions(+), 8 deletions(-) create mode 100644 .vs/config/applicationhost.config diff --git a/.vs/config/applicationhost.config b/.vs/config/applicationhost.config new file mode 100644 index 0000000..de613a4 --- /dev/null +++ b/.vs/config/applicationhost.config @@ -0,0 +1,1020 @@ + + + + + + + +
+
+
+
+
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+
+ + +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/JsonUtils/Controllers/HomeController.cs b/JsonUtils/Controllers/HomeController.cs index 5daaabb..90e0744 100644 --- a/JsonUtils/Controllers/HomeController.cs +++ b/JsonUtils/Controllers/HomeController.cs @@ -55,7 +55,7 @@ public ActionResult Index(string url) try { - vm.CodeObjects = Server.HtmlEncode(Prepare(vm.JSON, vm.ClassName, 1, vm.Nest, false, vm.PropertyAttribute)); + vm.CodeObjects = Server.HtmlEncode(Prepare(vm.JSON, vm.ClassName, 1, vm.Nest, false, vm.PropertyAttribute, vm.Namespace)); } catch (Exception ex) { @@ -108,9 +108,7 @@ public ActionResult Index(IndexViewModel model) if (model.Language != 3) { - model.CodeObjects = - Server.HtmlEncode(Prepare(model.JSON, model.ClassName, model.Language, model.Nest, model.Pascal, - model.PropertyAttribute, (model.Language == 5 || model.Language == 6) && model.Properties)); + model.CodeObjects = Server.HtmlEncode(Prepare(model.JSON, model.ClassName, model.Language, model.Nest, model.Pascal, model.PropertyAttribute, model.Namespace, (model.Language == 5 || model.Language == 6) && model.Properties)); } else model.CodeObjects = "javascript"; @@ -132,7 +130,7 @@ public ActionResult Index(IndexViewModel model) new TypeScriptCodeWriter() }; - private string Prepare(string JSON, string classname, int language, bool nest, bool pascal, string propertyAttribute, bool hasGetSet=false) + private string Prepare(string JSON, string classname, int language, bool nest, bool pascal, string propertyAttribute, string namesp, bool hasGetSet=false) { if (string.IsNullOrEmpty(JSON)) { @@ -160,7 +158,7 @@ private string Prepare(string JSON, string classname, int language, bool nest, b gen.CodeWriter = writer; gen.ExplicitDeserialization = false; if (nest) - gen.Namespace = "JSONUtils"; + gen.Namespace = namesp; else gen.Namespace = null; diff --git a/JsonUtils/ViewModels/IndexViewModel.cs b/JsonUtils/ViewModels/IndexViewModel.cs index 97cf8ce..dbcd08b 100644 --- a/JsonUtils/ViewModels/IndexViewModel.cs +++ b/JsonUtils/ViewModels/IndexViewModel.cs @@ -10,6 +10,8 @@ namespace Core.ViewModels public class IndexViewModel { public string ClassName { get; set; } + + public string Namespace { get; set; } public string JSON { get; set; } public List PropertyAttributeOptions diff --git a/JsonUtils/Views/Home/Index.cshtml b/JsonUtils/Views/Home/Index.cshtml index 71d2e28..6b26a1b 100644 --- a/JsonUtils/Views/Home/Index.cshtml +++ b/JsonUtils/Views/Home/Index.cshtml @@ -130,12 +130,18 @@ Get & Set - + + +
+ +
+ @Html.TextBoxFor(m => m.Namespace, new {placeholder = "Namespace", @class = "form-control"}) +
- @Html.DropDownListFor(m => m.PropertyAttribute, Model.PropertyAttributeOptions, new { @class = "form-control" }) + @Html.DropDownListFor(m => m.PropertyAttribute, Model.PropertyAttributeOptions, new { @class = "form-control" })
@@ -255,21 +261,25 @@ case 3: //Javascript $('#ClassName').attr('disabled', 'disabled'); $('#Nest').attr('disabled', 'disabled'); + $('#Namespace').attr('disabled', 'disabled'); $('#Pascal').attr('disabled', 'disabled'); $('#PropertyAttribute').attr('disabled', 'disabled'); break; case 4: //Sql $('#Nest').attr('disabled', 'disabled'); + $('#Namespace').attr('disabled', 'disabled'); $('#PropertyAttribute').attr('disabled', 'disabled'); break; case 5: //Java $('#Nest').attr('disabled', 'disabled'); + $('#Namespace').attr('disabled', 'disabled'); $('#Pascal').attr('disabled', 'disabled'); $('#PropertyAttribute').attr('disabled', 'disabled'); $("#div-properties").show(); break; case 6: //PHP $('#Nest').attr('disabled', 'disabled'); + $('#Namespace').attr('disabled', 'disabled'); $('#Pascal').attr('disabled', 'disabled'); $('#PropertyAttribute').attr('disabled', 'disabled'); $("#div-properties").show(); @@ -283,6 +293,14 @@ } } + function toggleNamespace(checked) { + if (checked) { + $('#Namespace').removeAttr('disabled'); + } + else + $('#Namespace').attr('disabled', 'disabled');; + } + function resetAttributes() { $('#ClassName').removeAttr('disabled'); $('#Nest').removeAttr('disabled'); @@ -359,10 +377,19 @@ disableAttributes(selectedValue); }); + $("#Nest").click(function () { + var namespaceCheck = $('#Nest').is(':checked'); + toggleNamespace(namespaceCheck); + }); + //Enable/Disable on ready var selectedValue = $('input:radio[name=Language]:checked').val(); disableAttributes(selectedValue); + //Namespace Enable/Disable + var namespaceCheck = $('#Nest').is(':checked'); + toggleNamespace(namespaceCheck); + //Attach event to copy contents of the sunlight editor to the clipboard var copierTitle = 'copy the generated code to your clipboard'; copier.attr('title', copierTitle); From b6baba9e2a6f95167e41f6d6711847049f2af0c3 Mon Sep 17 00:00:00 2001 From: "adis.kovacevic" Date: Fri, 19 May 2017 09:49:37 -0500 Subject: [PATCH 2/4] Added keyword check for c#, Java, VBbasic --- .vs/JsonUtils/v14/.suo | Bin 0 -> 12800 bytes .vs/config/applicationhost.config | 8 + .../CodeWriters/CSharpCodeWriter.cs | 110 +++++++++++ .../CodeWriters/JavaCodeWriter.cs | 62 ++++++ .../CodeWriters/PhpCodeWriter.cs | 2 + .../CodeWriters/SqlCodeWriter.cs | 5 +- .../CodeWriters/TypeScriptCodeWriter.cs | 2 + .../CodeWriters/VisualBasicCodeWriter.cs | 182 ++++++++++++++++++ JsonCSharpClassGeneratorLib/ICodeWriter.cs | 1 + .../JsonClassGeneratorLib.csproj | 8 +- JsonCSharpClassGeneratorLib/JsonExtentions.cs | 42 ++++ .../Properties/Resources.Designer.cs | 2 +- JsonCSharpClassGeneratorLib/packages.config | 2 +- JsonUtils/Controllers/HomeController.cs | 29 +++ JsonUtils/Views/Home/Index.cshtml | 4 + 15 files changed, 454 insertions(+), 5 deletions(-) create mode 100644 .vs/JsonUtils/v14/.suo create mode 100644 JsonCSharpClassGeneratorLib/JsonExtentions.cs diff --git a/.vs/JsonUtils/v14/.suo b/.vs/JsonUtils/v14/.suo new file mode 100644 index 0000000000000000000000000000000000000000..51bb3a7d65f518a1e53e94a90a6e2340410277ac GIT binary patch literal 12800 zcmeHNX>3$g6uvW36a^H-ihxqtt+sZ$(3T=n%E)3Bq=2zDU^`u)9oo_%>wnrR@?g;@Z~yB8y**Z(P^hw0EDQ7wC3er4vsF#~M*7rht1nYHrbB zF-!1pyl}Shr`m%@!?$Lm8|JGO#h-j@g%?jyC&~Z?&_ywzOwyU5VZ!M!F1Hz7Xn(y^ z@0lhRfs0qnhx~*J17|){TIdf$+T>5aiv!q|pFZv6k5Kvo{x%AL`sL`OPqPqnsp0`W z0lfj20jR%zfF6KL0gC@6sP_R}4N!Av6Lo!cN)5E9|JU{{On6oLzvw{!FMw@!`9G9^ zqKs1Q1N2$?Kl_#cn)(05pfmcvqNo2~X_#B_=)#>(13U(J6!Glt2H-wE9Kf~ZUar=c zYs>wgXE)CPw&_D$YuXOin|;bwxc~Q;eFK080tU(Ub-;rG39>x|cqm|)Y>xmQ2^b~Y ziNH4kZj$X};F|#{vYiUdb244FM+0X9vSfPxxJ6);}5CjjRGCd&40z>@%z z0aE}|0k;Dv-yOhr0;b9KUBEMBo#U}qtl|&qF;ZdtLA#;7Q1(c)YV2B6PRoWBf39Vu z0{(4#m|gzYW5VC$q*nZ0!WD_V7;z5#Z@`TEZ1bmen-}nRF#b|@XHFRyNka9oY(EgO|+4a9%=xCR;KWqNn#mx)-kLOTdfL;D>&^}JX zN3rIgtrMDjEBRHtV?q|xosX7X`BN=!fRsO4{Z9w~X8A-`@}~;x{fD}bM*afOZSPo#Z##L@uPL6?0{# ztPU$*ByQ6zhWWZW*axks96c3M(kG8?oZ)VH<$;8$2mGHtvp)sL#anFMw=C;ttf9fh?7Dxv<_~&q;@6X5x;MCPw3vBC-VJ@u$CFU6^wD5H{4b5} zXZ4jW`Aa@o`1h8%ZytzWzvYNg-<3GfpT<>E>78TeUN*Or{RPWyz5h(ntT0rAx^|9l zTJ!m=NrTs4JoeMoS3Gk6LQ1c+p|D+z9O|U>9Cx?tW5jQ^l!P9$Ay_3;$ zmRIi}TWdv|`Fw=KPLZfi;J~S2cETd!R>Xm=*%_{LmBXV&2#fHnY8QzdAutLEL(bkkpBV+a_kS1SwMd2hnUC)Su&e)DK>LxLG!WhC_P^7;ZF_m)AFbOLyu5tnYjb@h zQ?e;6f2yIqG3NhMac1&H8t{Nn4GdVBne)-@2P(c;;ryhc`o&)@G+=$Q3bJh<@! z9B!U4$DO{MOh@w6nXK;b3ah*R{vpF_PdscPBZo~&XSx5~4K;3HS zS(8p}T~jqMcWqA2PHpp1)~v9JfEL~B+R6R{K~|9_W$68v@9`NGm4%UhN1xTZYNkDx zz4qr1hrK_vvVkHgsjc?E$h$A!+3ERTz9;0I7V6T5d0rfpgjW0`XJ2*xd{4>ul6Lv? ztWf`dvEpxa|L6Ye#C*8W+UDO6wB6{HC|3Lldrcrdk#3h-^&M9QYtLO$(D!qCwdI z#Zs&;WK#oH_UF>xq?=E6F7Zz;rn4XaMD_siZ~HHrUH?DN?|*`<(p*!4k^Cs+ztHc0 z67!erJyh0ws^9F^rF=r=SqiIoLE(TDdTmEL?H|$R-&AtKcvlO(E9xQA$B*3k)tdJU zw{7}1-@nW?=j(7<2$ed}-rC9KSNS%#mNi)*^WlvZ?=AYid{Ewqr!sKAW2U$SS>bHd zJjf)c!{<{_D@N|vgHIVovb4N0DYG!121rFVcrs|Jktb$`#f@wW^DT9VPwMeuTwNk# z5?#}McTM^I`W1hzU!64}^_Qw1&l@$(`VW9!I2ZYc)>0g*%hB$MKPGJi{ucOc;GOuh z$-BUB#0jw(_)%Q`+@M$Xims?iXNg}YKvPPSyqg5aubKWI4-9H7J@eR<6bTJ+}rBMnav XKe~Ha=3y#Yt&qZP%15Q6 + + + + + + + + diff --git a/JsonCSharpClassGeneratorLib/CodeWriters/CSharpCodeWriter.cs b/JsonCSharpClassGeneratorLib/CodeWriters/CSharpCodeWriter.cs index 1a24b21..b9f2c3e 100644 --- a/JsonCSharpClassGeneratorLib/CodeWriters/CSharpCodeWriter.cs +++ b/JsonCSharpClassGeneratorLib/CodeWriters/CSharpCodeWriter.cs @@ -19,6 +19,11 @@ public string DisplayName get { return "C#"; } } + public IList Keywords + { + get { return _getKeywords(); } + } + private const string NoRenameAttribute = "[Obfuscation(Feature = \"renaming\", Exclude = true)]"; private const string NoPruneAttribute = "[Obfuscation(Feature = \"trigger\", Exclude = false)]"; @@ -222,6 +227,111 @@ private void WriteClassMembers(IJsonClassGeneratorConfig config, TextWriter sw, } + private List _getKeywords() + { + return new List {"abstract" + ,"add" + ,"as" + ,"ascending" + ,"async" + ,"await" + ,"base" + ,"bool" + ,"break " + ,"by " + ,"byte" + ,"case" + ,"catch" + ,"char" + ,"checked" + ,"class" + ,"const" + ,"continue" + ,"decimal" + ,"default" + ,"delegate" + ,"descending" + ,"do" + ,"double" + ,"dynamic" + ,"else" + ,"enum" + ,"equals" + ,"explicit" + ,"extern" + ,"false" + ,"finally" + ,"fixed" + ,"float" + ,"for" + ,"foreach" + ,"from" + ,"get" + ,"global" + ,"goto" + ,"group" + ,"if" + ,"implicit" + ,"in" + ,"int" + ,"interface" + ,"internal" + ,"into" + ,"is" + ,"join" + ,"let" + ,"lock" + ,"long" + ,"namespace" + ,"new" + ,"null" + ,"object" + ,"on" + ,"operator" + ,"orderby" + ,"out" + ,"override" + ,"params" + ,"partial" + ,"private" + ,"protected" + ,"public" + ,"readonly" + ,"ref" + ,"remove" + ,"return" + ,"sbyte" + ,"sealed" + ,"select" + ,"set" + ,"short" + ,"sizeof" + ,"stackalloc" + ,"static" + ,"string" + ,"struct" + ,"switch" + ,"this" + ,"throw" + ,"true" + ,"try" + ,"typeof" + ,"uint" + ,"ulong" + ,"unchecked" + ,"unsafe" + ,"ushort" + ,"using" + ,"value" + ,"var" + ,"virtual" + ,"void" + ,"volatile" + ,"where" + ,"while" + ,"yield"}; + } + diff --git a/JsonCSharpClassGeneratorLib/CodeWriters/JavaCodeWriter.cs b/JsonCSharpClassGeneratorLib/CodeWriters/JavaCodeWriter.cs index b17afb9..a0e5d0d 100644 --- a/JsonCSharpClassGeneratorLib/CodeWriters/JavaCodeWriter.cs +++ b/JsonCSharpClassGeneratorLib/CodeWriters/JavaCodeWriter.cs @@ -18,6 +18,8 @@ public string DisplayName get { return "Java"; } } + public IList Keywords { get {return _getKeywords();} } + public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config) { var arraysAsLists = !config.ExplicitDeserialization; @@ -199,5 +201,65 @@ private static string ChangeFirstChar(string value, bool toCaptial = true) return sb.ToString(); } + + private static List _getKeywords() + { + return new List() + { + "abstract", + "assert" , + "boolean", + "break", + "byte", + "case", + "catch", + "char", + "class", + "const", + "default", + "do", + "double", + "else", + "enum", + "extends", + "false", + "final", + "finally", + "float", + "for", + "goto", + "if", + "implements", + "import", + "instanceof", + "int", + "interface", + "long", + "native", + "new", + "null", + "package", + "private", + "protected", + "public", + "return", + "short", + "static", + "strictfp", + "super", + "switch", + "synchronized", + "this", + "throw", + "throws", + "transient", + "true", + "try", + "void", + "volatile", + "while", + "continue" + }; + } } } diff --git a/JsonCSharpClassGeneratorLib/CodeWriters/PhpCodeWriter.cs b/JsonCSharpClassGeneratorLib/CodeWriters/PhpCodeWriter.cs index 51fb0cc..a8b17e2 100644 --- a/JsonCSharpClassGeneratorLib/CodeWriters/PhpCodeWriter.cs +++ b/JsonCSharpClassGeneratorLib/CodeWriters/PhpCodeWriter.cs @@ -18,6 +18,8 @@ public string DisplayName get { return "PHP"; } } + public IList Keywords { get { return new List(); } } + public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config) { var arraysAsLists = !config.ExplicitDeserialization; diff --git a/JsonCSharpClassGeneratorLib/CodeWriters/SqlCodeWriter.cs b/JsonCSharpClassGeneratorLib/CodeWriters/SqlCodeWriter.cs index c248b55..56a7d7c 100644 --- a/JsonCSharpClassGeneratorLib/CodeWriters/SqlCodeWriter.cs +++ b/JsonCSharpClassGeneratorLib/CodeWriters/SqlCodeWriter.cs @@ -1,4 +1,5 @@ -using System.IO; +using System.Collections.Generic; +using System.IO; namespace Xamasoft.JsonClassGenerator.CodeWriters { @@ -14,6 +15,8 @@ public string DisplayName get { return "SQL"; } } + public IList Keywords { get { return new List(); } } + public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config) { var arraysAsLists = !config.ExplicitDeserialization; diff --git a/JsonCSharpClassGeneratorLib/CodeWriters/TypeScriptCodeWriter.cs b/JsonCSharpClassGeneratorLib/CodeWriters/TypeScriptCodeWriter.cs index 166a7b3..c86779e 100644 --- a/JsonCSharpClassGeneratorLib/CodeWriters/TypeScriptCodeWriter.cs +++ b/JsonCSharpClassGeneratorLib/CodeWriters/TypeScriptCodeWriter.cs @@ -18,6 +18,8 @@ public string DisplayName get { return "TypeScript"; } } + public IList Keywords { get { return new List(); } } + public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config) { switch (type.Type) diff --git a/JsonCSharpClassGeneratorLib/CodeWriters/VisualBasicCodeWriter.cs b/JsonCSharpClassGeneratorLib/CodeWriters/VisualBasicCodeWriter.cs index 5376b6e..f373de2 100644 --- a/JsonCSharpClassGeneratorLib/CodeWriters/VisualBasicCodeWriter.cs +++ b/JsonCSharpClassGeneratorLib/CodeWriters/VisualBasicCodeWriter.cs @@ -18,6 +18,8 @@ public string DisplayName get { return "Visual Basic .NET"; } } + public IList Keywords { get { return _getKeywords(); } } + private const string NoRenameAttribute = ""; private const string NoPruneAttribute = ""; @@ -164,5 +166,185 @@ public void WriteNamespaceEnd(IJsonClassGeneratorConfig config, TextWriter sw, b sw.WriteLine("End Namespace"); } + + private static List _getKeywords() + { + return new List() { "AddHandler" + ,"AddressOf" + ,"Alias" + ,"And" + ,"AndAlso" + ,"As" + ,"Boolean" + ,"ByRef" + ,"Byte" + ,"ByVal" + ,"Call" + ,"Case" + ,"Catch" + ,"CBool" + ,"CByte" + ,"CChar" + ,"CDate" + ,"CDec" + ,"CDbl" + ,"Char" + ,"CInt" + ,"Class" + ,"CLng" + ,"CObj" + ,"Const" + ,"Continue" + ,"CSByte" + ,"CShort" + ,"CSng" + ,"CStr" + ,"CType" + ,"CUInt" + ,"CULng" + ,"CUShort" + ,"Date" + ,"Decimal" + ,"Declare" + ,"Default" + ,"Delegate" + ,"Dim" + ,"DirectCast" + ,"Do" + ,"Double" + ,"Each" + ,"Else" + ,"ElseIf" + ,"End" + ,"EndIf" + ,"Enum" + ,"Erase" + ,"Error" + ,"Event" + ,"Exit" + ,"False" + ,"Finally" + ,"For" + ,"Friend" + ,"Function" + ,"Get" + ,"GetType" + ,"GetXMLNamespace" + ,"Global" + ,"GoSub" + ,"GoTo" + ,"Handles" + ,"If" + ,"If()" + ,"Implements" + ,"Imports" + ,"In" + ,"Inherits" + ,"Integer" + ,"Interface" + ,"Is" + ,"IsNot" + ,"Let" + ,"Lib" + ,"Like" + ,"Long" + ,"Loop" + ,"Me" + ,"Mod" + ,"Module" + ,"MustInherit" + ,"MustOverride" + ,"MyBase" + ,"MyClass" + ,"Namespace" + ,"Narrowing" + ,"New" + ,"Next" + ,"Not" + ,"Nothing" + ,"NotInheritable" + ,"NotOverridable" + ,"Object" + ,"Of" + ,"On" + ,"Operator" + ,"Option" + ,"Optional" + ,"Or" + ,"OrElse" + ,"Overloads" + ,"Overridable" + ,"Overrides" + ,"ParamArray" + ,"Partial" + ,"Private" + ,"Property" + ,"Protected" + ,"Public" + ,"RaiseEvent" + ,"ReadOnly" + ,"ReDim" + ,"REM" + ,"RemoveHandler" + ,"Resume" + ,"Return" + ,"SByte" + ,"Select" + ,"Set" + ,"Shadows" + ,"Shared" + ,"Short" + ,"Single" + ,"Static" + ,"Step" + ,"Stop" + ,"String" + ,"Structure" + ,"Sub" + ,"SyncLock" + ,"Then" + ,"Throw" + ,"To" + ,"True" + ,"Try" + ,"TryCast" + ,"TypeOf" + ,"Variant" + ,"Wend" + ,"UInteger" + ,"ULong" + ,"UShort" + ,"Using" + ,"When" + ,"While" + ,"Widening" + ,"With" + ,"WithEvents" + ,"WriteOnly" + ,"Xor" + ,"#Const" + ,"#Else" + ,"#ElseIf" + ,"#End" + ,"#If" + ,"=" + ,"&" + ,"&=" + ,"*" + ,"*=" + ,"/" + ,"/=" + ,@"\" + ,@"\=" + ,"^" + ,"^=" + ,"+" + ,"+=" + ,"-" + ,"-=" + ,">>" + ,"<<" + ,"<<="}; + } } } \ No newline at end of file diff --git a/JsonCSharpClassGeneratorLib/ICodeWriter.cs b/JsonCSharpClassGeneratorLib/ICodeWriter.cs index 5838daa..df32ddb 100644 --- a/JsonCSharpClassGeneratorLib/ICodeWriter.cs +++ b/JsonCSharpClassGeneratorLib/ICodeWriter.cs @@ -10,6 +10,7 @@ public interface ICodeWriter { string FileExtension { get; } string DisplayName { get; } + IList Keywords { get; } string GetTypeName(JsonType type, IJsonClassGeneratorConfig config); void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type); void WriteFileStart(IJsonClassGeneratorConfig config, TextWriter sw); diff --git a/JsonCSharpClassGeneratorLib/JsonClassGeneratorLib.csproj b/JsonCSharpClassGeneratorLib/JsonClassGeneratorLib.csproj index b33d1f8..b71fe24 100644 --- a/JsonCSharpClassGeneratorLib/JsonClassGeneratorLib.csproj +++ b/JsonCSharpClassGeneratorLib/JsonClassGeneratorLib.csproj @@ -1,5 +1,5 @@  - + Debug @@ -9,8 +9,9 @@ Properties Xamasoft.JsonClassGenerator Xamasoft.JsonClassGenerator - v3.5 + v4.5 512 + true @@ -20,6 +21,7 @@ DEBUG;TRACE prompt 4 + false pdbonly @@ -28,6 +30,7 @@ TRACE prompt 4 + false @@ -56,6 +59,7 @@ + True True diff --git a/JsonCSharpClassGeneratorLib/JsonExtentions.cs b/JsonCSharpClassGeneratorLib/JsonExtentions.cs new file mode 100644 index 0000000..4e2371b --- /dev/null +++ b/JsonCSharpClassGeneratorLib/JsonExtentions.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json.Linq; + +namespace Xamasoft.JsonClassGenerator +{ + public static class JsonExtentions + { + public static string Test() + { + return "asf"; + } + + private static IEnumerable WalkTokens(JToken node) + { + if (node == null) + yield break; + yield return node; + foreach (var child in node.Children()) + foreach (var childNode in WalkTokens(child)) + yield return childNode; + } + + public static HashSet ToHashSet(this JToken root) + { + var results = WalkTokens(root); + + var dictionary = new HashSet(); + + foreach (var result in results) + { + foreach (var child in result.Children()) + dictionary.Add(child.Name); + } + + return dictionary; + } + } +} diff --git a/JsonCSharpClassGeneratorLib/Properties/Resources.Designer.cs b/JsonCSharpClassGeneratorLib/Properties/Resources.Designer.cs index 63bd1a6..f586acb 100644 --- a/JsonCSharpClassGeneratorLib/Properties/Resources.Designer.cs +++ b/JsonCSharpClassGeneratorLib/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.18033 +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. diff --git a/JsonCSharpClassGeneratorLib/packages.config b/JsonCSharpClassGeneratorLib/packages.config index 9b49c9e..ef5508d 100644 --- a/JsonCSharpClassGeneratorLib/packages.config +++ b/JsonCSharpClassGeneratorLib/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/JsonUtils/Controllers/HomeController.cs b/JsonUtils/Controllers/HomeController.cs index 90e0744..484df0c 100644 --- a/JsonUtils/Controllers/HomeController.cs +++ b/JsonUtils/Controllers/HomeController.cs @@ -97,6 +97,11 @@ public ActionResult Index(IndexViewModel model) } } + if (_containsKeyword(model.JSON, model.Language)) + { + model.Error = true; + model.ErrorNo = 5; + } if (model.Error) { @@ -187,7 +192,31 @@ private string Prepare(string JSON, string classname, int language, bool nest, b } } + private bool _containsKeyword(string Json, int language) + { + ICodeWriter writer; + if (language == 1) + writer = new CSharpCodeWriter(); + else if (language == 2) + writer = new VisualBasicCodeWriter(); + else if (language == 7) + writer = new TypeScriptCodeWriter(); + else if (language == 4) + writer = new SqlCodeWriter(); + else if (language == 5) + writer = new JavaCodeWriter(); + else + writer = new PhpCodeWriter(); + + var jtoken = JToken.Parse(Json); + var hashSet = jtoken.ToHashSet(); + + if (writer.Keywords.Any(x => hashSet.Contains(x))) + return true; + + return false; + } public string Result { get; set; } diff --git a/JsonUtils/Views/Home/Index.cshtml b/JsonUtils/Views/Home/Index.cshtml index 6b26a1b..7e06278 100644 --- a/JsonUtils/Views/Home/Index.cshtml +++ b/JsonUtils/Views/Home/Index.cshtml @@ -34,6 +34,10 @@ { Invalid URL. Unable to download JSON data or URL is not valid JSON } + else if (Model.ErrorNo == 5) + { + JSON contains a Keyword for the choosen langauge + } } From ac6857b19f519415dbc34e71d981ce43fae29dc9 Mon Sep 17 00:00:00 2001 From: Adis Kovacevic Date: Tue, 6 Jun 2017 08:52:18 -0500 Subject: [PATCH 3/4] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8ff6f32..01c2249 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ # JsonUtils Json to C#, VB.Net, Javascript and SQL Server Table -Powers [JsonUtils.com](http://jsonutils.com) +Powers [JsonUtils.adiskovacevic.com](http://jsonutils.adiskovacevic.com) + +Updated from [JsonUtils.com](http://jsonutils.com) Code may be a bit messy, was always intended for personal use! Accepting Pull Requests. -Uses & Relies on [Json Class Generator](https://jsonclassgenerator.codeplex.com/) \ No newline at end of file +Uses & Relies on [Json Class Generator](https://jsonclassgenerator.codeplex.com/) From d1016bcf63b29e3b210a83859bef28fea0833ed1 Mon Sep 17 00:00:00 2001 From: Adis Kovacevic Date: Wed, 14 Jun 2017 11:55:37 -0500 Subject: [PATCH 4/4] Create README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 01c2249..9e8dc4a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # JsonUtils Json to C#, VB.Net, Javascript and SQL Server Table -Powers [JsonUtils.adiskovacevic.com](http://jsonutils.adiskovacevic.com) +Powers [JsonUtil.adiskovacevic.com](http://jsonutil.adiskovacevic.com) Updated from [JsonUtils.com](http://jsonutils.com)