Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/19/19 16:59:18 (5 years ago)
Author:
dpiringe
Message:

#3026:

  • relocated BuildJsonItem from JCInstantiator into JsonItem
  • in JsonItem: removed JContainer usage in setter for Value (now in BuildJsonItem)
File:
1 edited

Legend:

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

    r17353 r17354  
    8383    private static void CollectParameterizedItems(InstData instData) {
    8484      foreach (JObject item in instData.Template[Constants.Objects]) {
    85         JsonItem data = BuildJsonItem(item, instData);
     85        JsonItem data = JsonItem.BuildJsonItem(item, instData.TypeList);
    8686        instData.ParameterizedItems.Add(data.Path, data);
    8787      }
     
    120120      foreach (JObject obj in instData.Config) {
    121121        // build item from config object
    122         JsonItem item = BuildJsonItem(obj, instData);
     122        JsonItem item = JsonItem.BuildJsonItem(obj, instData.TypeList);
    123123        // override default value
    124124        if (instData.ConfigurableItems.TryGetValue(item.Path, out JsonItem param)) {
     
    145145      } else throw new TypeLoadException($"Cannot find AssemblyQualifiedName for {data.Name}.");
    146146    }
    147 
    148     #region BuildJsonItemMethods
    149     private static JsonItem BuildJsonItem(JObject obj, InstData instData) =>
    150       new JsonItem() {
    151         Name = obj[nameof(JsonItem.Name)]?.ToString(),
    152         Path = obj[nameof(JsonItem.Path)]?.ToString(),
    153         Value = obj[nameof(JsonItem.Value)]?.ToObject<object>(),
    154         Range = obj[nameof(JsonItem.Range)]?.ToObject<object[]>(),
    155         Type = GetType(obj[nameof(JsonItem.Path)]?.ToObject<string>(), instData),
    156         ActualName = obj[nameof(JsonItem.ActualName)]?.ToString(),
    157         Parameters = PopulateParameters(obj, instData),
    158         Operators = PopulateOperators(obj, instData)
    159       };
    160 
    161     private static string GetType(string path, InstData instData) {
    162       if(!string.IsNullOrEmpty(path))
    163         if (instData.TypeList.TryGetValue(path, out string value))
    164           return value;
    165       return null;
    166     }
    167 
    168     private static IList<JsonItem> PopulateParameters(JObject obj, InstData instData) {
    169       IList<JsonItem> list = new List<JsonItem>();
    170 
    171       // add staticParameters
    172       if (obj[Constants.StaticParameters] != null)
    173         foreach (JObject param in obj[Constants.StaticParameters])
    174           list.Add(BuildJsonItem(param, instData));
    175 
    176       // merge staticParameter with freeParameter
    177       if (obj[Constants.FreeParameters] != null) {
    178         foreach (JObject param in obj[Constants.FreeParameters]) {
    179           JsonItem tmp = BuildJsonItem(param, instData);
    180          
    181           // search staticParameter from list
    182           JsonItem comp = null;
    183           foreach (var p in list)
    184             if (p.Name == tmp.Name) comp = p;
    185           if (comp == null)
    186             throw new InvalidDataException($"Invalid {Constants.FreeParameters.Trim('s')}: '{tmp.Name}'!");
    187 
    188           JsonItem.Merge(comp, tmp);
    189         }
    190       }
    191       return list;
    192     }
    193 
    194     private static IList<JsonItem> PopulateOperators(JObject obj, InstData instData) {
    195       IList<JsonItem> list = new List<JsonItem>();
    196       JToken operators = obj[nameof(JsonItem.Operators)];
    197       if (operators != null)
    198         foreach (JObject sp in operators)
    199           list.Add(BuildJsonItem(sp, instData));
    200       return list;
    201     }
    202     #endregion
    203147    #endregion
    204148  }
Note: See TracChangeset for help on using the changeset viewer.