Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
EnumProperty.cs
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4
6{
10 public class EnumProperty : Property
11 {
12 private readonly Type enumType;
13 private readonly TypeInfo enumTypeInfo;
14 private readonly bool asInt;
15
19 internal EnumProperty(Type EnumType)
20 : base()
21 {
22 this.enumType = EnumType;
23 this.enumTypeInfo = EnumType.GetTypeInfo();
24 this.asInt = this.enumTypeInfo.IsDefined(typeof(FlagsAttribute), false);
25 }
26
30 public override Type PropertyType => this.enumType;
31
37 public override void Serialize(Serializer Output, object Value)
38 {
39 if (this.asInt)
40 Output.WriteInt32((int)Value);
41 else
42 Output.WriteString(Value.ToString());
43 }
44
51 public override object Deserialize(Deserializer Input, Type ExpectedType)
52 {
53 if (this.asInt)
54 return Enum.ToObject(this.enumType, Input.ReadInt32());
55 else
56 return Enum.Parse(this.enumType, Input.ReadString());
57 }
58 }
59}
int ReadInt32()
Reads a 32-bit signed integer from the input.
string ReadString()
Reads a string from the input.
Definition: Deserializer.cs:99
override void Serialize(Serializer Output, object Value)
Serializes the property value of an object.
Definition: EnumProperty.cs:37
override object Deserialize(Deserializer Input, Type ExpectedType)
Deserializes the property value
Definition: EnumProperty.cs:51
void WriteInt32(int Value)
Writes a 32-bit signed integer to the output.
Definition: Serializer.cs:157
void WriteString(string Value)
Writes a string to the output.
Definition: Serializer.cs:118