예제 #1
0
        /// <summary>
        /// Json type converted.
        /// </summary>
        /// <param name="generator">The generator config.</param>
        /// <param name="token">The json token.</param>
        public JsonType(IJsonConfig generator, JToken token)
            : this(generator)
        {
            Type = GetFirstTypeEnum(token);

            if (Type == JsonTypeEnum.Array)
            {
                var array = (JArray)token;
                InternalType = GetCommonType(generator, array.ToArray());
            }
        }
예제 #2
0
 /// <summary>
 /// JSON field info.
 /// </summary>
 /// <param name="generator">The genrator.</param>
 /// <param name="jsonMemberName">The json memeber name.</param>
 /// <param name="type">The json type.</param>
 /// <param name="usePascalCase">Use pacal case.</param>
 /// <param name="jobjects">The json objects.</param>
 public JsonFieldInfo(IJsonConfig generator, string jsonMemberName, JsonType type, bool usePascalCase, IList <object> jobjects)
 {
     this.generator      = generator;
     this.JsonMemberName = jsonMemberName;
     this.MemberName     = jsonMemberName;
     if (usePascalCase)
     {
         MemberName = JsonGenerator.ToTitleCase(MemberName);
     }
     this.Type     = type;
     this.Jobjects = jobjects;
 }
예제 #3
0
        /// <summary>
        /// Get common type
        /// </summary>
        /// <param name="generator">The generator config.</param>
        /// <param name="tokens">The json tokens.</param>
        /// <returns>The json type.</returns>
        public static JsonType GetCommonType(IJsonConfig 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);
        }
예제 #4
0
 /// <summary>
 /// Json type converted.
 /// </summary>
 /// <param name="generator">The generator config.</param>
 /// <param name="assignedName">The assigned name.</param>
 private JsonType(IJsonConfig generator, string assignedName)
 {
     this.generator = generator;
     AssignedName   = assignedName;
     Type           = JsonTypeEnum.Object;
 }
예제 #5
0
 /// <summary>
 /// Json type converted.
 /// </summary>
 /// <param name="generator">The generator config.</param>
 private JsonType(IJsonConfig generator)
 {
     this.generator = generator;
 }
예제 #6
0
 /// <summary>
 /// Set the internal type null value and only assign the assignment name.
 /// </summary>
 /// <param name="generator">The generator config.</param>
 /// <param name="assignedName">The assigned name.</param>
 internal void SetInternalType(IJsonConfig generator, string assignedName)
 {
     InternalType = new JsonType(generator, assignedName);
 }
예제 #7
0
 /// <summary>
 /// Make nullable.
 /// </summary>
 /// <param name="generator">The generator config.</param>
 /// <returns>The json type.</returns>
 internal JsonType MaybeMakeNullable(IJsonConfig generator)
 {
     return(this.GetCommonType(JsonType.GetNull(generator)));
 }
예제 #8
0
 /// <summary>
 /// Get nullables.
 /// </summary>
 /// <param name="generator">The generator config.</param>
 /// <returns>The null able type.</returns>
 internal static JsonType GetNull(IJsonConfig generator)
 {
     return(new JsonType(generator, JsonTypeEnum.NullableSomething));
 }
예제 #9
0
 /// <summary>
 /// Json type converted.
 /// </summary>
 /// <param name="generator">The generator config.</param>
 /// <param name="type">The json type.</param>
 internal JsonType(IJsonConfig generator, JsonTypeEnum type)
     : this(generator)
 {
     this.Type = type;
 }
예제 #10
0
        public static string FormatAndColorize(IJsonConfig config, string jsonData)
        {
            config = config ?? throw new ArgumentNullException(nameof(config));

            if (jsonData == null)
            {
                return(string.Empty);
            }

            StringBuilder result = new StringBuilder();

            using (JsonTextReader reader = new JsonTextReader(new StringReader(jsonData)))
            {
                bool isValuePosition = false;
                bool isTerminalValue = false;
                bool isFirstToken    = true;

                while (reader.Read())
                {
                    if (!isValuePosition)
                    {
                        //If we're about to write an end object/array, we shouldn't have a comma
                        if (reader.TokenType != JsonToken.EndArray && reader.TokenType != JsonToken.EndObject &&
                            isTerminalValue)
                        {
                            result.Append(",".SetColor(config.CommaColor));
                        }

                        if (!isFirstToken)
                        {
                            result.AppendLine();
                        }
                    }

                    isFirstToken = false;

                    if (!isValuePosition)
                    {
                        result.Append("".PadLeft(reader.Depth * config.IndentSize));
                    }

                    isTerminalValue = false;
                    isValuePosition = false;
                    JsonToken type = reader.TokenType;

                    switch (type)
                    {
                    case JsonToken.StartObject:
                        result.Append("{".SetColor(config.ObjectBraceColor));
                        break;

                    case JsonToken.EndObject:
                        result.Append("}".SetColor(config.ObjectBraceColor));
                        isTerminalValue = true;
                        break;

                    case JsonToken.StartArray:
                        result.Append("[".SetColor(config.ArrayBraceColor));
                        break;

                    case JsonToken.EndArray:
                        result.Append("]".SetColor(config.ArrayBraceColor));
                        isTerminalValue = true;
                        break;

                    case JsonToken.PropertyName:
                        result.Append((reader.QuoteChar.ToString() + reader.Value + reader.QuoteChar).SetColor(config.NameColor) + ": ".SetColor(config.NameSeparatorColor));
                        isValuePosition = true;
                        break;

                    case JsonToken.Boolean:
                        result.Append(reader.Value.ToString().ToLowerInvariant().SetColor(config.BoolColor));
                        isTerminalValue = true;
                        break;

                    case JsonToken.Integer:
                    case JsonToken.Float:
                        result.Append(reader.Value.ToString().ToLowerInvariant().SetColor(config.NumericColor));
                        isTerminalValue = true;
                        break;

                    case JsonToken.Null:
                        result.Append("null".SetColor(config.NullColor));
                        isTerminalValue = true;
                        break;

                    case JsonToken.Comment:
                        result.Append(("//" + reader.Value).SetColor(config.NumericColor));
                        break;

                    case JsonToken.String:
                        result.Append((reader.QuoteChar.ToString() + reader.Value + reader.QuoteChar.ToString()).SetColor(config.StringColor));
                        isTerminalValue = true;
                        break;

                    case JsonToken.Raw:
                    case JsonToken.Date:
                    case JsonToken.Bytes:
                    case JsonToken.Undefined:
                    case JsonToken.None:
                        result.Append(reader.Value.ToString().SetColor(config.DefaultColor));
                        isTerminalValue = true;
                        break;

                    case JsonToken.EndConstructor:
                    case JsonToken.StartConstructor:
                    default:
                        result.Append(reader.Value.ToString().SetColor(config.DefaultColor));
                        break;
                    }
                }
            }
            return(result.ToString());
        }
예제 #11
0
 public GitReportCreator(IJsonConfig jsonConfig)
 {
     this.componentDictionary = new Dictionary <HashId, ComponentData>();
     this.commitDictionary    = new Dictionary <string, CommitData>();
     this.jsonConfig          = jsonConfig;
 }
예제 #12
0
 public DfTestContext(ITenantFactory tenantFactory, IJsonConfig jsonConfig) : base(tenantFactory)
 {
     _jsonConfig = jsonConfig;
 }