Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3026_IntegrationIntoSymSpace/HeuristicLab.JsonInterface/Models/GenericJsonItem.cs @ 17417

Last change on this file since 17417 was 17417, checked in by dpiringe, 4 years ago

#3026:

  • added initial VM (ArrayValueVM) and control for array values (JsonItemArrayValueControl)
  • new types of JsonItems for better type safety:
    • for arrays: DoubleArrayJsonItem, IntArrayJsonItem, BoolArrayJsonItem
    • for matrix: DoubleMatrixJsonItem, IntMatrixJsonItem, BoolMatrixJsonItem
  • refactored ValueTypeArrayConverter and ValueTypeMatrixConverter -> better type safety with new JsonItems
  • enhanced StringValueVM and implemented JsonItemValidValuesControl with MVVM architecture
  • the VM of JsonItemBaseControl is now protected (was private)
  • improved JsonItem<V,R> -> now handles JTokens correctly
File size: 766 bytes
Line 
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7using Newtonsoft.Json.Linq;
8
9namespace HeuristicLab.JsonInterface {
10
11  public class JsonItem<T> : JsonItem<T,T> { }
12
13  public class JsonItem<V,R> : JsonItem {
14    public new V Value {
15      get {
16        if(base.Value is IConvertible)
17          return (V)Convert.ChangeType(base.Value, typeof(V));
18
19        if(base.Value is JToken token)
20          return token.ToObject<V>();
21
22        return (V)base.Value;
23      }
24      set => base.Value = value;
25    }
26
27    public new IEnumerable<R> Range {
28      get => base.Range?.Cast<R>();
29      set => base.Range = value.Cast<object>();
30    }
31  }
32}
Note: See TracBrowser for help on using the repository browser.