Last change
on this file since 17464 was
17433,
checked in by dpiringe, 5 years ago
|
#3026:
- added property Description in IJsonItem and updated all construction calls
- updated UnsupportedJsonItem with unsupported property Description
- updated JsonItemBaseControl and JsonItemVMBase for new property Description
|
File size:
998 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Threading.Tasks;
|
---|
6 | using HeuristicLab.Core;
|
---|
7 | using HeuristicLab.Data;
|
---|
8 |
|
---|
9 | namespace HeuristicLab.JsonInterface {
|
---|
10 | public class EnumTypeConverter : BaseConverter {
|
---|
11 | public override int Priority => 1;
|
---|
12 | public override Type ConvertableType => typeof(EnumValue<>);
|
---|
13 |
|
---|
14 | public override void Inject(IItem item, IJsonItem data, IJsonItemConverter root) =>
|
---|
15 | ((dynamic)item).Value = Enum.Parse(
|
---|
16 | item.GetType().GenericTypeArguments.First(),
|
---|
17 | ((StringJsonItem)data).Value);
|
---|
18 |
|
---|
19 | public override IJsonItem Extract(IItem value, IJsonItemConverter root) {
|
---|
20 | object val = ((dynamic)value).Value;
|
---|
21 | Type enumType = val.GetType();
|
---|
22 | return new StringJsonItem() {
|
---|
23 | Name = value.ItemName,
|
---|
24 | Description = value.ItemDescription,
|
---|
25 | Value = Enum.GetName(enumType, val),
|
---|
26 | Range = Enum.GetNames(enumType)
|
---|
27 | };
|
---|
28 | }
|
---|
29 | }
|
---|
30 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.