BadScript 2
Loading...
Searching...
No Matches
BadReflectedField.cs
Go to the documentation of this file.
1using System.Reflection;
2
6
8
13{
17 private readonly FieldInfo m_Info;
18
23 public BadReflectedField(FieldInfo field) : base(field.Name)
24 {
25 m_Info = field;
26 }
27
29 public override bool IsReadOnly => m_Info.IsInitOnly;
30
32 public override BadObject Get(object instance)
33 {
34 return Wrap(m_Info.GetValue(instance));
35 }
36
38 public override void Set(object instance, BadObject o)
39 {
40 if (o is not IBadNative native || !m_Info.FieldType.IsAssignableFrom(native.Type))
41 {
42 throw new BadRuntimeException("Invalid Reflection Set");
43 }
44
45 m_Info.SetValue(instance, native.Value);
46 }
47}
BadReflectedField(FieldInfo field)
Creates a new BadReflectedField.
static BadObject Wrap(object? o)
Wraps an Object into a BadObject.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Defines properties for Native Types.
Definition IBadNative.cs:7
Contains the Error Objects for the BadScript2 Language.
Contains the Member Classes for Reflection Objects.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10