Free cookie consent management tool by TermsFeed Policy Generator

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

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

#3026:

  • renamed JsonItemArrayValueControl to JsonItemMultiValueControl
  • extracted converter logic from property Value in JsonItem<V,R> into new private method ConvertObject
  • added references to TreeNode and TreeView in JsonItemVMBase -> for additional user feedback when enabling/disabling an item (changes the fore color of referenced node)
  • changed implementation and interplay between ArrayValueVM and JsonItemMultiValueControl -> removed the direct access of property DataSource of DataGridView -> now: dynamically adds new columns/rows and accesses grid cells manually (better handling with matrices)
  • added new VM MatrixValueVM
File size: 805 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 => ConvertObject(base.Value);
16      set => base.Value = value;
17    }
18   
19    public new IEnumerable<R> Range {
20      get => base.Range?.Cast<R>();
21      set => base.Range = value.Cast<object>();
22    }
23
24    private V ConvertObject(object obj) {
25      if (obj is IConvertible)
26        return (V)Convert.ChangeType(obj, typeof(V));
27
28      if (obj is JToken token)
29        return token.ToObject<V>();
30
31      return (V)obj;
32    }
33  }
34}
Note: See TracBrowser for help on using the repository browser.