BadScript 2
Loading...
Searching...
No Matches
BadNative.cs
Go to the documentation of this file.
3
5
10public class BadNative<T> : BadObject, IBadNative
11{
16 typeof(T).Name,
17 (_, args) =>
18 {
19 if (args.Length != 1 || args[0] is not BadNative<T> t)
20 {
21 throw new BadRuntimeException("BadNative<T> constructor takes one argument of type BadNative<T>");
22 }
23
24 return t;
25 }
26 );
27
31 private readonly T m_Value;
32
33
39 public BadNative(T value)
40 {
41 if (value == null)
42 {
43 throw new Exception("Can not construct native object with null value");
44 }
45
46 m_Value = value;
47 }
48
52 public T Value => m_Value;
53
57 object IBadNative.Value => m_Value!;
58
62 Type IBadNative.Type => m_Value!.GetType();
63
64
70 public bool Equals(IBadNative? other)
71 {
72 if (other is null)
73 {
74 return false;
75 }
76
77 IBadNative thisN = this;
78
79 return thisN.Value.Equals(other.Value);
80 }
81
83 public override int GetHashCode()
84 {
85 return EqualityComparer<T>.Default.GetHashCode(Value!);
86 }
87
88
90 public override string ToSafeString(List<BadObject> done)
91 {
92 return m_Value!.ToString()!;
93 }
94
101 public static bool operator ==(BadNative<T> a, BadObject b)
102 {
103 return a.Equals(b);
104 }
105
112 public static bool operator !=(BadNative<T> a, BadObject b)
113 {
114 return !(a == b);
115 }
116
122 public override bool Equals(object? obj)
123 {
124 return obj is IBadNative other && Equals(other);
125 }
126
129 {
130 return s_Prototype;
131 }
132
134 public override bool HasProperty(string propName, BadScope? caller = null)
135 {
136 return caller != null && caller.Provider.HasObject<T>(propName);
137 }
138
140 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
141 {
143 $"BadNative<{typeof(T).Name}>.{propName}",
144 () => caller != null
145 ? caller.Provider.GetObject<T>(propName, this, caller)
146 : throw BadRuntimeException.Create(caller, $"No property named {propName} for type {GetType().Name}")
147 );
148 }
149}
Implements the Scope for the Script Engine.
Definition BadScope.cs:238
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
Implements the base functionality for a BadScript Reference.
static BadObjectReference Make(string refText, Func< BadObject > getter, Action< BadObject, BadPropertyInfo?>? setter=null, Action? delete=null)
Creates a new Reference Object.
static bool operator!=(BadNative< T > a, BadObject b)
Implements the != operator.
Definition BadNative.cs:112
static readonly BadClassPrototype s_Prototype
The Prototype for the Native Type.
Definition BadNative.cs:15
T Value
The Value of the Native Type.
Definition BadNative.cs:52
override string ToSafeString(List< BadObject > done)
Definition BadNative.cs:90
BadNative(T value)
Creates a new Native Type.
Definition BadNative.cs:39
override bool Equals(object? obj)
Returns true if this and the other objects are equal.
Definition BadNative.cs:122
bool Equals(IBadNative? other)
Returns true if this and the other native types are equal.
Definition BadNative.cs:70
static bool operator==(BadNative< T > a, BadObject b)
Implements the == operator.
Definition BadNative.cs:101
override bool HasProperty(string propName, BadScope? caller=null)
Returns true if the object contains a given property or there exists an extension for the current Ins...
Definition BadNative.cs:134
Type IBadNative. Type
The Type of the Native Type.
Definition BadNative.cs:62
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
Definition BadNative.cs:140
override BadClassPrototype GetPrototype()
Definition BadNative.cs:128
readonly T m_Value
The Value of the Native Type.
Definition BadNative.cs:31
Implements a Class Prototype for the BadScript Language.
Defines properties for Native Types.
Definition IBadNative.cs:7
object Value
The Value of the Native Object.
Definition IBadNative.cs:11
Contains the Error Objects for the BadScript2 Language.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6