public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type)
        {
            var visibility = config.InternalVisibility ? "Friend" : "Public";

            if (config.UseNestedClasses)
            {
                sw.WriteLine("    {0} Partial Class {1}", visibility, config.MainClass);
                if (!type.IsRoot)
                {
                    if (ShouldApplyNoRenamingAttribute(config)) sw.WriteLine("        " + NoRenameAttribute);
                    if (ShouldApplyNoPruneAttribute(config)) sw.WriteLine("        " + NoPruneAttribute);
                    sw.WriteLine("        {0} Class {1}", visibility, type.AssignedName);
                }
            }
            else
            {
                if (ShouldApplyNoRenamingAttribute(config)) sw.WriteLine("    " + NoRenameAttribute);
                if (ShouldApplyNoPruneAttribute(config)) sw.WriteLine("    " + NoPruneAttribute);
                sw.WriteLine("    {0} Class {1}", visibility, type.AssignedName);
            }

            var prefix = config.UseNestedClasses && !type.IsRoot ? "            " : "        ";

            WriteClassMembers(config, sw, type, prefix);

            if (config.UseNestedClasses && !type.IsRoot)
                sw.WriteLine("        End Class");

            sw.WriteLine("    End Class");
            sw.WriteLine();
        }
        public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config)
        {
            var arraysAsLists = config.ExplicitDeserialization;

            switch (type.Type)
            {
                case JsonTypeEnum.Anything: return "Object";
                case JsonTypeEnum.Array: return arraysAsLists ? "IList(Of " + GetTypeName(type.InternalType, config) + ")" : GetTypeName(type.InternalType, config) + "()";
                case JsonTypeEnum.Dictionary: return "Dictionary(Of String, " + GetTypeName(type.InternalType, config) + ")";
                case JsonTypeEnum.Boolean: return "Boolean";
                case JsonTypeEnum.Float: return "Double";
                case JsonTypeEnum.Integer: return "Integer";
                case JsonTypeEnum.Long: return "Long";
                case JsonTypeEnum.Date: return "DateTime";
                case JsonTypeEnum.NonConstrained: return "Object";
                case JsonTypeEnum.NullableBoolean: return "Boolean?";
                case JsonTypeEnum.NullableFloat: return "Double?";
                case JsonTypeEnum.NullableInteger: return "Integer?";
                case JsonTypeEnum.NullableLong: return "Long?";
                case JsonTypeEnum.NullableDate: return "DateTime?";
                case JsonTypeEnum.NullableSomething: return "Object";
                case JsonTypeEnum.Object: return type.AssignedName;
                case JsonTypeEnum.String: return "String";
                default: throw new System.NotSupportedException("Unsupported json type");
            }
        }
Exemple #3
0
        public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type)
        {
            var visibility = "public";

            sw.WriteLine();
            sw.WriteLine("package {0};",config.Namespace );
            if (config.UseNestedClasses)
            {
                if (!type.IsRoot)
                {
                    if (ShouldApplyNoRenamingAttribute(config)) sw.WriteLine("        " + NoRenameAttribute);
                    if (ShouldApplyNoPruneAttribute(config)) sw.WriteLine("        " + NoPruneAttribute);
                    sw.WriteLine("        {0} class {1}", visibility, type.AssignedName);
                    sw.WriteLine("        {");
                }
            }
            else
            {
                if (ShouldApplyNoRenamingAttribute(config)) sw.WriteLine("    " + NoRenameAttribute);
                if (ShouldApplyNoPruneAttribute(config)) sw.WriteLine("    " + NoPruneAttribute);
                sw.WriteLine("    {0} class {1}", visibility, type.AssignedName);
                sw.WriteLine("    {");
            }

            var prefix = config.UseNestedClasses && !type.IsRoot ? "            " : "        ";

            var shouldSuppressWarning = config.InternalVisibility && !config.UseProperties && !config.ExplicitDeserialization;
            if (shouldSuppressWarning)
            {
                sw.WriteLine("#pragma warning disable 0649");
                if (!config.UsePascalCase) sw.WriteLine();
            }

            if (type.IsRoot && config.ExplicitDeserialization) WriteStringConstructorExplicitDeserialization(config, sw, type, prefix);

            if (config.ExplicitDeserialization)
            {
                if (config.UseProperties) WriteClassWithPropertiesExplicitDeserialization(sw, type, prefix);
                else WriteClassWithFieldsExplicitDeserialization(sw, type, prefix);
            }
            else
            {
                WriteClassMembers(config, sw, type, prefix);
            }

            if (shouldSuppressWarning)
            {
                sw.WriteLine();
                sw.WriteLine("#pragma warning restore 0649");
                sw.WriteLine();
            }

            if (config.UseNestedClasses && !type.IsRoot)
                sw.WriteLine("        }");

            if (!config.UseNestedClasses)
                sw.WriteLine("    }");

            sw.WriteLine();
        }
 public void WriteFileStart(IJsonClassGeneratorConfig config, TextWriter sw)
 {
     foreach (var line in JsonClassGenerator.FileHeader)
     {
         sw.WriteLine("// " + line);
     }
 }
        public void WriteFileStart(IJsonClassGeneratorConfig config, TextWriter sw)
        {
            if (config.UseNamespaces)
            {
                foreach (var line in JsonClassGenerator.FileHeader)
                {
                    sw.WriteLine("// " + line);
                }
                sw.WriteLine();
                sw.WriteLine("using System;");
                sw.WriteLine("using System.Collections.Generic;");
                if (ShouldApplyNoPruneAttribute(config) || ShouldApplyNoRenamingAttribute(config))
                    sw.WriteLine("using System.Reflection;");
                if (!config.ExplicitDeserialization && config.UsePascalCase)
                    sw.WriteLine("using Newtonsoft.Json;");
                sw.WriteLine("using Newtonsoft.Json.Linq;");
                if (config.ExplicitDeserialization)
                    sw.WriteLine("using JsonCSharpClassGenerator;");
                if (config.SecondaryNamespace != null && config.HasSecondaryClasses && !config.UseNestedClasses)
                {
                    sw.WriteLine("using {0};", config.SecondaryNamespace);
                }
            }

            if (config.UseNestedClasses)
            {
                sw.WriteLine("    {0} class {1}", config.InternalVisibility ? "internal" : "public", config.MainClass);
                sw.WriteLine("    {");
            }
        }
Exemple #6
0
        public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config)
        {
            var arraysAsLists = !config.ExplicitDeserialization;

            switch (type.Type)
            {
                case JsonTypeEnum.Anything: return "object";
                case JsonTypeEnum.Array: return arraysAsLists ? "IList<" + GetTypeName(type.InternalType, config) + ">" : GetTypeName(type.InternalType, config) + "[]";
                case JsonTypeEnum.Dictionary: return "Dictionary<string, " + GetTypeName(type.InternalType, config) + ">";
                case JsonTypeEnum.Boolean: return "bit NOT NULL";
                case JsonTypeEnum.Float: return "[decimal](9,2) NOT NULL";
                case JsonTypeEnum.Integer: return "[int] NOT NULL";
                case JsonTypeEnum.Long: return "[bigint] NOT NULL";
                case JsonTypeEnum.Date: return "[datetime]";
                case JsonTypeEnum.NonConstrained: return "object";
                case JsonTypeEnum.NullableBoolean: return "bit NULL";
                case JsonTypeEnum.NullableFloat: return "[decimal](9,2) NULL";
                case JsonTypeEnum.NullableInteger: return "[int] NULL";
                case JsonTypeEnum.NullableLong: return "[bigint] NULL";
                case JsonTypeEnum.NullableDate: return "[datetime] NULL";
                case JsonTypeEnum.NullableSomething: return "object NULL";
                case JsonTypeEnum.Object: return type.AssignedName;
                case JsonTypeEnum.String: return "[varchar](50) NULL";
                default: throw new System.NotSupportedException("Unsupported json type");
            }
        }
Exemple #7
0
 public void WriteFileEnd(IJsonClassGeneratorConfig config, TextWriter sw)
 {
     if (config.UseNestedClasses)
     {
         sw.WriteLine("    }");
     }
 }
        public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config)
        {
            var arraysAsLists = !config.ExplicitDeserialization;

            switch (type.Type)
            {
                case JsonTypeEnum.Anything: return "object";
                case JsonTypeEnum.Array: return arraysAsLists ? "IList<" + GetTypeName(type.InternalType, config) + ">" : GetTypeName(type.InternalType, config) + "[]";
                case JsonTypeEnum.Dictionary: return "Dictionary<string, " + GetTypeName(type.InternalType, config) + ">";
                case JsonTypeEnum.Boolean: return "bool";
                case JsonTypeEnum.Float: return "double";
                case JsonTypeEnum.Integer: return "int";
                case JsonTypeEnum.Long: return "long";
                case JsonTypeEnum.Date: return "DateTime";
                case JsonTypeEnum.NonConstrained: return "object";
                case JsonTypeEnum.NullableBoolean: return "bool?";
                case JsonTypeEnum.NullableFloat: return "double?";
                case JsonTypeEnum.NullableInteger: return "int?";
                case JsonTypeEnum.NullableLong: return "long?";
                case JsonTypeEnum.NullableDate: return "DateTime?";
                case JsonTypeEnum.NullableSomething: return "object";
                case JsonTypeEnum.Object: return type.AssignedName;
                case JsonTypeEnum.String: return "string";
                default: throw new NotSupportedException("Unsupported json type");
            }
        }
 public void WriteNamespaceEnd(IJsonClassGeneratorConfig config, TextWriter sw, bool root)
 {
     if (GetNamespace(config, root) != null)
     {
         sw.WriteLine("}");
         sw.WriteLine();
     }
 }
Exemple #10
0
 public FieldInfo(IJsonClassGeneratorConfig generator, string jsonMemberName, JsonType type, bool usePascalCase, IList<object> Examples)
 {
     this.generator = generator;
     this.JsonMemberName = jsonMemberName;
     this.MemberName = jsonMemberName;
     if (usePascalCase) MemberName = JsonCSharpClassGenerator.JsonClassGenerator.ToTitleCase(MemberName);
     this.Type = type;
     this.Examples = Examples;
 }
Exemple #11
0
        public JsonType(IJsonClassGeneratorConfig generator, JToken token)
            : this(generator)
        {
            Type = GetFirstTypeEnum(token);

            if (Type == JsonTypeEnum.Array)
            {
                var array = (JArray)token;
                InternalType = GetCommonType(generator, array.ToArray());
            }
        }
Exemple #12
0
        private void WriteClassMembers(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type)
        {
            foreach (var field in type.Fields)
            {              
                if (config.UseProperties)
                {
                    string typeName = field.Type.InternalType == null 
                        ? field.Type.GetTypeName() 
                        : field.Type.InternalType.GetTypeName();

                    sw.WriteLine("    [{0}] {1},", field.MemberName, typeName);
                }
            }
        }
Exemple #13
0
        public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type)
        {
            sw.WriteLine("create table " + type.AssignedName + " (");
            sw.WriteLine("    [Id] [int] IDENTITY(1,1) NOT NULL,");

            WriteClassMembers(config, sw, type);

            sw.WriteLine("CONSTRAINT [PK_" + type.AssignedName + "] PRIMARY KEY CLUSTERED");
            sw.WriteLine("   (");
            sw.WriteLine("      [Id] asc");
            sw.WriteLine("   )");
            sw.WriteLine(")");

            sw.WriteLine();
        }
Exemple #14
0
        public static JsonType GetCommonType(IJsonClassGeneratorConfig generator, JToken[] tokens)
        {

            if (tokens.Length == 0) return new JsonType(generator, JsonTypeEnum.NonConstrained);

            var common = new JsonType(generator, tokens[0]).MaybeMakeNullable(generator);

            for (int i = 1; i < tokens.Length; i++)
            {
                var current = new JsonType(generator, tokens[i]);
                common = common.GetCommonType(current);
            }

            return common;

        }
        public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type)
        {
            var prefix = GetNamespace(config, type.IsRoot) != null ? "    " : "";
            var exported = !config.InternalVisibility || config.SecondaryNamespace != null;
            sw.WriteLine(prefix + (exported ? "export " : string.Empty) + "interface " + type.AssignedName + " {");
            foreach (var field in type.Fields)
            {
                var shouldDefineNamespace = type.IsRoot && config.SecondaryNamespace != null && config.Namespace != null && (field.Type.Type == JsonTypeEnum.Object || (field.Type.InternalType != null && field.Type.InternalType.Type == JsonTypeEnum.Object));
                if (config.ExamplesInDocumentation)
                {
                    sw.WriteLine();
                    sw.WriteLine(prefix + "    /**");
                    sw.WriteLine(prefix + "      * Examples: " + field.GetExamplesText());
                    sw.WriteLine(prefix + "      */");
                }

                sw.WriteLine(prefix + "    " + field.JsonMemberName + (IsNullable(field.Type.Type) ? "?" : "") + ": " + (shouldDefineNamespace ? config.SecondaryNamespace + "." : string.Empty) + GetTypeName(field.Type, config) + ";");
            }
            sw.WriteLine(prefix + "}");
            sw.WriteLine();
        }
 public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config)
 {
     switch (type.Type)
     {
         case JsonTypeEnum.Anything: return "any";
         case JsonTypeEnum.String: return "string";
         case JsonTypeEnum.Boolean: return "bool";
         case JsonTypeEnum.Integer:
         case JsonTypeEnum.Long:
         case JsonTypeEnum.Float: return "number";
         case JsonTypeEnum.Date: return "Date";
         case JsonTypeEnum.NullableInteger:
         case JsonTypeEnum.NullableLong:
         case JsonTypeEnum.NullableFloat: return "number";
         case JsonTypeEnum.NullableBoolean: return "bool";
         case JsonTypeEnum.NullableDate: return "Date";
         case JsonTypeEnum.Object: return type.AssignedName;
         case JsonTypeEnum.Array: return GetTypeName(type.InternalType, config) + "[]";
         case JsonTypeEnum.Dictionary: return "{ [key: string]: " + GetTypeName(type.InternalType, config) + "; }";
         case JsonTypeEnum.NullableSomething: return "any";
         case JsonTypeEnum.NonConstrained: return "any";
         default: throw new NotSupportedException("Unsupported type");
     }
 }
Exemple #17
0
 public void WriteFileEnd(IJsonClassGeneratorConfig config, StringBuilder sw)
 {
 }
Exemple #18
0
 public void WriteNamespaceEnd(IJsonClassGeneratorConfig config, StringBuilder sb, bool root)
 {
     throw new NotImplementedException();
 }
        public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type)
        {
            string arg = config.InternalVisibility ? "internal" : "public";

            if (config.UseNestedClasses)
            {
                if (!type.IsRoot)
                {
                    if (this.ShouldApplyNoRenamingAttribute(config))
                    {
                        sw.WriteLine("        [Obfuscation(Feature = \"renaming\", Exclude = true)]");
                    }
                    if (this.ShouldApplyNoPruneAttribute(config))
                    {
                        sw.WriteLine("        [Obfuscation(Feature = \"trigger\", Exclude = false)]");
                    }
                    sw.WriteLine("        {0} class {1} ", arg, type.AssignedName);
                    sw.WriteLine("        {");
                }
            }
            else
            {
                if (this.ShouldApplyNoRenamingAttribute(config))
                {
                    sw.WriteLine("    [Obfuscation(Feature = \"renaming\", Exclude = true)]");
                }
                if (this.ShouldApplyNoPruneAttribute(config))
                {
                    sw.WriteLine("    [Obfuscation(Feature = \"trigger\", Exclude = false)]");
                }
                sw.WriteLine("    {0} class {1} ", arg, type.AssignedName);
                sw.WriteLine("    {");
            }
            string prefix = (config.UseNestedClasses && !type.IsRoot) ? "            " : "        ";
            bool   flag   = config.InternalVisibility && !config.UseProperties && !config.ExplicitDeserialization;

            if (flag)
            {
                sw.WriteLine("#pragma warning disable 0649");
                if (!config.UsePascalCase)
                {
                    sw.WriteLine();
                }
            }
            if (type.IsRoot && config.ExplicitDeserialization)
            {
                this.WriteStringConstructorExplicitDeserialization(config, sw, type, prefix);
            }
            if (config.ExplicitDeserialization)
            {
                if (config.UseProperties)
                {
                    this.WriteClassWithPropertiesExplicitDeserialization(sw, type, prefix);
                }
                else
                {
                    this.WriteClassWithFieldsExplicitDeserialization(sw, type, prefix);
                }
            }
            else
            {
                this.WriteClassMembers(config, sw, type, prefix);
            }
            if (flag)
            {
                sw.WriteLine();
                sw.WriteLine("#pragma warning restore 0649");
                sw.WriteLine();
            }
            if (config.UseNestedClasses && !type.IsRoot)
            {
                sw.WriteLine("        }");
            }
            if (!config.UseNestedClasses)
            {
                sw.WriteLine("    }");
            }
            sw.WriteLine();
        }
        public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config)
        {
            bool flag = !config.ExplicitDeserialization;

            switch (type.Type)
            {
            case JsonTypeEnum.Anything:
                return("object");

            case JsonTypeEnum.String:
                return("string");

            case JsonTypeEnum.Boolean:
                return("bool");

            case JsonTypeEnum.Integer:
                return("int");

            case JsonTypeEnum.Long:
                return("long");

            case JsonTypeEnum.Float:
                return("float");

            case JsonTypeEnum.Date:
                return("DateTime");

            case JsonTypeEnum.NullableInteger:
                return("int?");

            case JsonTypeEnum.NullableLong:
                return("long?");

            case JsonTypeEnum.NullableFloat:
                return("double?");

            case JsonTypeEnum.NullableBoolean:
                return("bool?");

            case JsonTypeEnum.NullableDate:
                return("DateTime?");

            case JsonTypeEnum.Object:
                return(type.AssignedName);

            case JsonTypeEnum.Array:
                if (!flag)
                {
                    return(this.GetTypeName(type.InternalType, config) + "[]");
                }
                return("IList<" + this.GetTypeName(type.InternalType, config) + ">");

            case JsonTypeEnum.Dictionary:
                return("Dictionary<string, " + this.GetTypeName(type.InternalType, config) + ">");

            case JsonTypeEnum.NullableSomething:
                return("object");

            case JsonTypeEnum.NonConstrained:
                return("object");

            default:
                throw new NotSupportedException("Unsupported json type");
            }
        }
Exemple #21
0
 private JsonType(IJsonClassGeneratorConfig generator)
 {
     this.generator = generator;
 }
Exemple #22
0
 public void WriteNamespaceStart(IJsonClassGeneratorConfig config, StringBuilder sw, Boolean root)
 {
     return;
 }
Exemple #23
0
 internal static JsonType GetNull(IJsonClassGeneratorConfig generator)
 {
     return new JsonType(generator, JsonTypeEnum.NullableSomething);
 }
 public void WriteNamespaceEnd(IJsonClassGeneratorConfig config, TextWriter sw, bool root)
 {
     throw new NotImplementedException();
 }
 public void WriteFileEnd(IJsonClassGeneratorConfig config, TextWriter sw)
 {
     throw new NotImplementedException();
 }
 public string GetTypeName(JsonType type, IJsonClassGeneratorConfig config)
 {
     throw new NotImplementedException();
 }
 public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type)
 {
     throw new NotImplementedException();
 }
 public void WriteFileEnd(IJsonClassGeneratorConfig config, TextWriter sw)
 {
 }
 private string GetNamespace(IJsonClassGeneratorConfig config, bool root)
 {
     return(root ? config.Namespace : (config.SecondaryNamespace ?? config.Namespace));
 }
 private bool ShouldApplyNoPruneAttribute(IJsonClassGeneratorConfig config)
 {
     return(config.ApplyObfuscationAttributes && !config.ExplicitDeserialization && config.UseProperties);
 }
 public static bool HasNamespace(this IJsonClassGeneratorConfig config) => !String.IsNullOrEmpty(config.Namespace);
        public void WriteNamespaceStart(IJsonClassGeneratorConfig config, TextWriter sw, bool root)
        {
            if (GetNamespace(config, root) != null)
            {

                sw.WriteLine("module " + GetNamespace(config, root) + " {");
                sw.WriteLine();
            }
        }
Exemple #33
0
 public void WriteNamespaceEnd(IJsonClassGeneratorConfig config, StringBuilder sw, bool root)
 {
     sw.AppendLine("}");
 }
 public void WriteNamespaceStart(IJsonClassGeneratorConfig config, TextWriter sw, bool root)
 {
     sw.WriteLine();
     sw.WriteLine("Namespace Global.{0}", root && !config.UseNestedClasses ? config.Namespace : (config.SecondaryNamespace ?? config.Namespace));
     sw.WriteLine();
 }
Exemple #35
0
 public void WriteFileStart(IJsonClassGeneratorConfig config, StringBuilder sw)
 {
     return;
 }
 private string GetNamespace(IJsonClassGeneratorConfig config, bool root)
 {
     return root ? config.Namespace : (config.SecondaryNamespace ?? config.Namespace);
 }
Exemple #37
0
 internal JsonType MaybeMakeNullable(IJsonClassGeneratorConfig generator)
 {
     if (!generator.AlwaysUseNullableValues) return this;
     return this.GetCommonType(JsonType.GetNull(generator));
 }
Exemple #38
0
 private bool ShouldApplyNoPruneAttribute(IJsonClassGeneratorConfig config)
 {
     return(config.ApplyObfuscationAttributes && (config.OutputType == OutputTypes.MutableClass && config.MutableClasses.Members == OutputMembers.AsPublicFields));
 }
Exemple #39
0
 internal JsonType(IJsonClassGeneratorConfig generator, JsonTypeEnum type)
     : this(generator)
 {
     this.Type = type;
 }
 internal JsonType MaybeMakeNullable(IJsonClassGeneratorConfig generator)
 {
     if (!generator.AlwaysUseNullableValues) return this;
     return this.GetCommonType(JsonType.GetNull(generator));
 }
Exemple #41
0
 public void WriteDeserializationComment(IJsonClassGeneratorConfig config, StringBuilder sw, bool rootIsArray = false)
 {
     return;
 }
Exemple #42
0
 public void WriteFileEnd(IJsonClassGeneratorConfig config, StringBuilder sb)
 {
     throw new NotImplementedException();
 }
Exemple #43
0
        public void WriteNamespaceStart(IJsonClassGeneratorConfig config, TextWriter sw, bool root)
        {

        }
Exemple #44
0
 private bool ShouldApplyNoRenamingAttribute(IJsonClassGeneratorConfig config)
 {
     return(config.ApplyObfuscationAttributes && !config.ExplicitDeserialization && !config.UsePascalCase);
 }
 private bool ShouldApplyNoRenamingAttribute(IJsonClassGeneratorConfig config)
 {
     return config.ApplyObfuscationAttributes && !config.ExplicitDeserialization && !config.UsePascalCase;
 }
Exemple #46
0
 public void WriteNamespaceStart(IJsonClassGeneratorConfig config, TextWriter sw, bool root)
 {
 }
 private void WriteProperty(IJsonClassGeneratorConfig config, TextWriter sw, string prefix, FieldInfo field, bool shouldDefineNamespace)
 {
     sw.WriteLine(prefix + "    " + field.JsonMemberName + (IsNullable(field.Type.Type) ? "?" : "") + ": " +
                  (shouldDefineNamespace ? config.SecondaryNamespace + "." : string.Empty) + GetTypeName(field.Type, config) + ";");
 }
 public void WriteFileEnd(IJsonClassGeneratorConfig config, TextWriter sw)
 {
 }
 public void WriteNamespaceStart(IJsonClassGeneratorConfig config, TextWriter sw, bool root)
 {
     sw.WriteLine();
     sw.WriteLine("package {0};", root && !config.UseNestedClasses ? config.Namespace : (config.SecondaryNamespace ?? config.Namespace));
     sw.WriteLine();
 }
Exemple #50
0
 public void WriteNamespaceStart(IJsonClassGeneratorConfig config, StringBuilder sw, bool root)
 {
     sw.AppendLine();
     sw.AppendFormat("package {0};", root && !config.UseNestedClasses ? config.Namespace : (config.SecondaryNamespace ?? config.Namespace));
     sw.AppendLine();
 }
 public void WriteNamespaceEnd(IJsonClassGeneratorConfig config, TextWriter sw, bool root)
 {
     sw.WriteLine("End Namespace");
 }
Exemple #52
0
 private JsonType(IJsonClassGeneratorConfig generator)
 {
     this.generator = generator;
 }
 private bool ShouldApplyNoPruneAttribute(IJsonClassGeneratorConfig config)
 {
     return config.ApplyObfuscationAttributes && !config.ExplicitDeserialization && config.UseProperties;
 }
Exemple #54
0
 internal static JsonType GetNull(IJsonClassGeneratorConfig generator)
 {
     return(new JsonType(generator, JsonTypeEnum.NullableSomething));
 }
        private void WriteClassMembers(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type, string prefix)
        {
            foreach (var field in type.Fields)
            {
                if (config.UsePascalCase || config.ExamplesInDocumentation) sw.WriteLine();

                if (config.ExamplesInDocumentation)
                {
                    sw.WriteLine(prefix + "''' <summary>");
                    sw.WriteLine(prefix + "''' Examples: " + field.GetExamplesText());
                    sw.WriteLine(prefix + "''' </summary>");
                }

                if (config.UsePascalCase)
                {
                    sw.WriteLine(prefix + "<JsonProperty(\"{0}\")>", field.JsonMemberName);
                }

                if (config.UseProperties)
                {
                    sw.WriteLine(prefix + "Public Property {1} As {0}", field.Type.GetTypeName(), field.MemberName);
                }
                else
                {
                    sw.WriteLine(prefix + "Public {1} As {0}", field.Type.GetTypeName(), field.MemberName);
                }
            }
        }
Exemple #56
0
 internal JsonType(IJsonClassGeneratorConfig generator, JsonTypeEnum type)
     : this(generator)
 {
     this.Type = type;
 }
Exemple #57
0
 public void WriteNamespaceEnd(IJsonClassGeneratorConfig config, TextWriter sw, bool root)
 {
     sw.WriteLine("}");
 }
Exemple #58
0
        public void WriteClass(IJsonClassGeneratorConfig config, TextWriter sw, JsonType type)
        {
            var visibility = config.InternalVisibility ? "internal" : "public";



            if (config.UseNestedClasses)
            {
                if (!type.IsRoot)
                {
                    if (ShouldApplyNoRenamingAttribute(config))
                    {
                        sw.WriteLine("        " + NoRenameAttribute);
                    }
                    if (ShouldApplyNoPruneAttribute(config))
                    {
                        sw.WriteLine("        " + NoPruneAttribute);
                    }
                    sw.WriteLine("        {0} class {1}", visibility, type.AssignedName);
                    sw.WriteLine("        {");
                }
            }
            else
            {
                if (ShouldApplyNoRenamingAttribute(config))
                {
                    sw.WriteLine("    " + NoRenameAttribute);
                }
                if (ShouldApplyNoPruneAttribute(config))
                {
                    sw.WriteLine("    " + NoPruneAttribute);
                }
                sw.WriteLine("    {0} class {1}", visibility, type.AssignedName);
                sw.WriteLine("    {");
            }

            var prefix = config.UseNestedClasses && !type.IsRoot ? "            " : "        ";


            var shouldSuppressWarning = config.InternalVisibility && !config.UseProperties && !config.ExplicitDeserialization;

            if (shouldSuppressWarning)
            {
                sw.WriteLine("#pragma warning disable 0649");
                if (!config.UsePascalCase)
                {
                    sw.WriteLine();
                }
            }

            if (type.IsRoot && config.ExplicitDeserialization)
            {
                WriteStringConstructorExplicitDeserialization(config, sw, type, prefix);
            }

            if (config.ExplicitDeserialization)
            {
                if (config.UseProperties)
                {
                    WriteClassWithPropertiesExplicitDeserialization(sw, type, prefix);
                }
                else
                {
                    WriteClassWithFieldsExplicitDeserialization(sw, type, prefix);
                }
            }
            else
            {
                WriteClassMembers(config, sw, type, prefix);
            }

            if (shouldSuppressWarning)
            {
                sw.WriteLine();
                sw.WriteLine("#pragma warning restore 0649");
                sw.WriteLine();
            }


            if (config.UseNestedClasses && !type.IsRoot)
            {
                sw.WriteLine("        }");
            }

            if (!config.UseNestedClasses)
            {
                sw.WriteLine("    }");
            }

            sw.WriteLine();
        }
 public void WriteFileStart(IJsonClassGeneratorConfig config, TextWriter sw)
 {
     sw.WriteLine("Imports System");
     sw.WriteLine("Imports System.Collections.Generic");
     if (ShouldApplyNoRenamingAttribute(config) || ShouldApplyNoPruneAttribute(config))
         sw.WriteLine("Imports System.Reflection");
     if (config.UsePascalCase)
         sw.WriteLine("Imports Newtonsoft.Json");
     sw.WriteLine("Imports Newtonsoft.Json.Linq");
     if (config.SecondaryNamespace != null && config.HasSecondaryClasses && !config.UseNestedClasses)
     {
         sw.WriteLine("Imports {0}", config.SecondaryNamespace);
     }
 }
Exemple #60
0
 public void WriteClass(IJsonClassGeneratorConfig config, StringBuilder sb, JsonType type)
 {
     throw new NotImplementedException();
 }