Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
EnumSetting.cs
1using System;
4
6{
10 public class EnumSetting : Setting
11 {
12 private Enum value = null;
13 private Type enumType = null;
14 private string enumTypeName = string.Empty;
15 private string enumValue = string.Empty;
16
20 public EnumSetting()
21 {
22 }
23
29 public EnumSetting(string Key, Enum Value)
30 : base(Key)
31 {
32 this.Value = Value;
33 }
34
38 [IgnoreMember]
39 public Enum Value
40 {
41 get
42 {
43 if (this.value is null)
44 this.value = (Enum)Enum.Parse(this.enumType, this.enumValue);
45
46 return this.value;
47 }
48
49 set
50 {
51 this.enumType = value.GetType();
52 this.enumTypeName = this.enumType.FullName;
53 this.enumValue = value.ToString();
54 this.value = null;
55 }
56 }
57
61 [DefaultValueStringEmpty]
62 public string EnumTypeName
63 {
64 get => this.enumTypeName;
65 set
66 {
67 this.enumType = Types.GetType(value);
68 if (this.enumType is null)
69 throw new InvalidOperationException("Enumeration type not recognized by " + typeof(Types).Namespace + ": " + value);
70
71 this.enumTypeName = value;
72 this.value = null;
73 }
74 }
75
79 [DefaultValueStringEmpty]
80 public string EnumValue
81 {
82 get => this.enumValue;
83 set
84 {
85 this.enumValue = value;
86 this.value = null;
87 }
88 }
89
94 public override object GetValueObject()
95 {
96 return this.Value;
97 }
98 }
99}
Static class that dynamically manages types and interfaces available in the runtime environment.
Definition: Types.cs:14
static Type GetType(string FullName)
Gets a type, given its full name.
Definition: Types.cs:41
EnumSetting()
Enumeration setting object.
Definition: EnumSetting.cs:20
EnumSetting(string Key, Enum Value)
Enumeration setting object.
Definition: EnumSetting.cs:29
override object GetValueObject()
Gets the value of the setting, as an object.
Definition: EnumSetting.cs:94
Base abstract class for settings.
Definition: Setting.cs:14