Last change
on this file since 17530 was
17519,
checked in by dpiringe, 5 years ago
|
#3026:
- added error output for failed runner initialization
- reorganised some final view models
- TargetedJsonItemType (in JsonItemVMBase) now automatically returns the type of the defined JsonItem
- code cleanup
- refactored RegressionProblemDataConverter
- added lots of comments
- added new view for StringArrayJsonItem
- added new UI component for concrete restricted items and used it in JsonItemConcreteItemArrayControl and JsonItemValidValuesControl
|
File size:
971 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using Newtonsoft.Json.Linq;
|
---|
3 |
|
---|
4 | namespace HeuristicLab.JsonInterface {
|
---|
5 | public abstract class ValueJsonItem : JsonItem, IValueJsonItem {
|
---|
6 | public object Value { get; set; }
|
---|
7 |
|
---|
8 | public override void SetJObject(JObject jObject) {
|
---|
9 | Value = jObject[nameof(IValueJsonItem.Value)]?.ToObject<object>();
|
---|
10 | }
|
---|
11 |
|
---|
12 | }
|
---|
13 |
|
---|
14 | public abstract class ValueJsonItem<T> : ValueJsonItem, IValueJsonItem<T> {
|
---|
15 | public new T Value {
|
---|
16 | get => ConvertObject(base.Value);
|
---|
17 | set => base.Value = value;
|
---|
18 | }
|
---|
19 |
|
---|
20 | private T ConvertObject(object obj) {
|
---|
21 | if (obj is IConvertible)
|
---|
22 | return (T)Convert.ChangeType(obj, typeof(T));
|
---|
23 |
|
---|
24 | if (obj is JToken token)
|
---|
25 | return token.ToObject<T>();
|
---|
26 |
|
---|
27 | return (T)obj;
|
---|
28 | }
|
---|
29 |
|
---|
30 | public override void SetJObject(JObject jObject) {
|
---|
31 | if(jObject[nameof(IValueJsonItem<T>.Value)] != null)
|
---|
32 | Value = jObject[nameof(IValueJsonItem<T>.Value)].ToObject<T>();
|
---|
33 | }
|
---|
34 | }
|
---|
35 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.