- Timestamp:
- 01/27/20 10:33:01 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItem.cs
r17404 r17406 14 14 /// Main data class for json interface. 15 15 /// </summary> 16 public class JsonItem { 17 public class JsonItemValidator { 16 public class JsonItem : IJsonItem { 17 18 public class JsonItemValidator : IJsonItemValidator { 18 19 private IDictionary<int, bool> Cache = new Dictionary<int, bool>(); 19 20 private JsonItem Root { get; set; } … … 22 23 } 23 24 24 public bool Validate(ref IList< JsonItem> faultyItems) {25 faultyItems = new List< JsonItem>();25 public bool Validate(ref IList<IJsonItem> faultyItems) { 26 faultyItems = new List<IJsonItem>(); 26 27 return ValidateHelper(Root, ref faultyItems); 27 28 } 28 29 29 private bool ValidateHelper(JsonItem item, ref IList< JsonItem> faultyItems) {30 private bool ValidateHelper(JsonItem item, ref IList<IJsonItem> faultyItems) { 30 31 int hash = item.GetHashCode(); 31 32 if (Cache.TryGetValue(hash, out bool r)) … … 38 39 Cache.Add(hash, res); 39 40 foreach (var child in item.Children) 40 res = res && ValidateHelper(child , ref faultyItems);41 res = res && ValidateHelper(child as JsonItem, ref faultyItems); 41 42 return res; 42 43 } … … 47 48 public virtual string Path { 48 49 get { 49 JsonItem tmp = Parent;50 IJsonItem tmp = Parent; 50 51 StringBuilder builder = new StringBuilder(this.Name); 51 52 while(tmp != null) { … … 58 59 59 60 [JsonIgnore] 60 public virtual IList< JsonItem> Children { get; protected set; }61 public virtual IList<IJsonItem> Children { get; protected set; } 61 62 62 63 [JsonIgnore] 63 public virtual JsonItem Parent { get; set; }64 public virtual IJsonItem Parent { get; set; } 64 65 65 66 public virtual object Value { get; set; } … … 72 73 public JsonItem() { } 73 74 74 public JsonItem(IEnumerable< JsonItem> childs) {75 public JsonItem(IEnumerable<IJsonItem> childs) { 75 76 AddChilds(childs); 76 77 } 77 78 #endregion 78 79 79 80 80 #region Public Static Methods … … 86 86 if(target.Children != null) { 87 87 if (from.Children != null) 88 ((List< JsonItem>)from.Children).AddRange(target.Children);88 ((List<IJsonItem>)from.Children).AddRange(target.Children); 89 89 } else { 90 90 target.Children = from.Children; … … 94 94 95 95 #region Public Methods 96 public void AddChilds(params JsonItem[] childs) =>97 AddChilds(childs as IEnumerable< JsonItem>);96 public void AddChilds(params IJsonItem[] childs) => 97 AddChilds(childs as IEnumerable<IJsonItem>); 98 98 99 public void AddChilds(IEnumerable< JsonItem> childs) {99 public void AddChilds(IEnumerable<IJsonItem> childs) { 100 100 if (Children == null) 101 Children = new List< JsonItem>();101 Children = new List<IJsonItem>(); 102 102 foreach (var child in childs) { 103 103 Children.Add(child); … … 106 106 } 107 107 108 public virtual JsonItemValidator GetValidator() => new JsonItemValidator(this);108 public virtual IJsonItemValidator GetValidator() => new JsonItemValidator(this); 109 109 #endregion 110 110 … … 154 154 155 155 #region BuildJsonItemMethods 156 public static JsonItem BuildJsonItem(JObject obj) {156 public static IJsonItem BuildJsonItem(JObject obj) { 157 157 object val = obj[nameof(Value)]?.ToObject<object>(); 158 158 if (val is JContainer jContainer) // for resolving array values
Note: See TracChangeset
for help on using the changeset viewer.