/// <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()); } }
/// <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; }
/// <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); }
/// <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; }
/// <summary> /// Json type converted. /// </summary> /// <param name="generator">The generator config.</param> private JsonType(IJsonConfig generator) { this.generator = generator; }
/// <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); }
/// <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))); }
/// <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)); }
/// <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; }
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()); }
public GitReportCreator(IJsonConfig jsonConfig) { this.componentDictionary = new Dictionary <HashId, ComponentData>(); this.commitDictionary = new Dictionary <string, CommitData>(); this.jsonConfig = jsonConfig; }
public DfTestContext(ITenantFactory tenantFactory, IJsonConfig jsonConfig) : base(tenantFactory) { _jsonConfig = jsonConfig; }