Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/27/20 10:33:01 (4 years ago)
Author:
dpiringe
Message:

#3026

  • added interfaces IJsonItem and IJsonItemValidator
  • replaced every reference JsonItem with IJsonItem
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/JsonItem.cs

    r17404 r17406  
    1414  /// Main data class for json interface.
    1515  /// </summary>
    16   public class JsonItem {
    17     public class JsonItemValidator {
     16  public class JsonItem : IJsonItem {
     17
     18    public class JsonItemValidator : IJsonItemValidator {
    1819      private IDictionary<int, bool> Cache = new Dictionary<int, bool>();
    1920      private JsonItem Root { get; set; }
     
    2223      }
    2324
    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>();
    2627        return ValidateHelper(Root, ref faultyItems);
    2728      }
    2829
    29       private bool ValidateHelper(JsonItem item, ref IList<JsonItem> faultyItems) {
     30      private bool ValidateHelper(JsonItem item, ref IList<IJsonItem> faultyItems) {
    3031        int hash = item.GetHashCode();
    3132        if (Cache.TryGetValue(hash, out bool r))
     
    3839        Cache.Add(hash, res);
    3940        foreach (var child in item.Children)
    40           res = res && ValidateHelper(child, ref faultyItems);
     41          res = res && ValidateHelper(child as JsonItem, ref faultyItems);
    4142        return res;
    4243      }
     
    4748    public virtual string Path {
    4849      get {
    49         JsonItem tmp = Parent;
     50        IJsonItem tmp = Parent;
    5051        StringBuilder builder = new StringBuilder(this.Name);
    5152        while(tmp != null) {
     
    5859
    5960    [JsonIgnore]
    60     public virtual IList<JsonItem> Children { get; protected set; }
     61    public virtual IList<IJsonItem> Children { get; protected set; }
    6162
    6263    [JsonIgnore]
    63     public virtual JsonItem Parent { get; set; }
     64    public virtual IJsonItem Parent { get; set; }
    6465
    6566    public virtual object Value { get; set; }
     
    7273    public JsonItem() { }
    7374
    74     public JsonItem(IEnumerable<JsonItem> childs) {
     75    public JsonItem(IEnumerable<IJsonItem> childs) {
    7576      AddChilds(childs);
    7677    }
    7778    #endregion
    78 
    7979
    8080    #region Public Static Methods
     
    8686      if(target.Children != null) {
    8787        if (from.Children != null)
    88           ((List<JsonItem>)from.Children).AddRange(target.Children);
     88          ((List<IJsonItem>)from.Children).AddRange(target.Children);
    8989      } else {
    9090        target.Children = from.Children;
     
    9494
    9595    #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>);
    9898
    99     public void AddChilds(IEnumerable<JsonItem> childs) {
     99    public void AddChilds(IEnumerable<IJsonItem> childs) {
    100100      if (Children == null)
    101         Children = new List<JsonItem>();
     101        Children = new List<IJsonItem>();
    102102      foreach (var child in childs) {
    103103        Children.Add(child);
     
    106106    }
    107107
    108     public virtual JsonItemValidator GetValidator() => new JsonItemValidator(this);
     108    public virtual IJsonItemValidator GetValidator() => new JsonItemValidator(this);
    109109    #endregion
    110110
     
    154154
    155155    #region BuildJsonItemMethods
    156     public static JsonItem BuildJsonItem(JObject obj) {
     156    public static IJsonItem BuildJsonItem(JObject obj) {
    157157      object val = obj[nameof(Value)]?.ToObject<object>();
    158158      if (val is JContainer jContainer) // for resolving array values
Note: See TracChangeset for help on using the changeset viewer.