BadScript 2
Loading...
Searching...
No Matches
BadMemberInfo.cs
Go to the documentation of this file.
7
8namespace BadScript2.Runtime;
9
11{
14 (c, a) => throw BadRuntimeException.Create(c.Scope,
15 "MemberInfo is a read only object"
16 )
17 );
18
19 private readonly Lazy<BadObjectReference> m_GetAttributesReference;
20 private readonly Lazy<BadObjectReference> m_GetValueReference;
21 private readonly Lazy<BadObjectReference> m_IsReadonlyReference;
22 private readonly Lazy<BadObjectReference> m_MemberTypeReference;
23 private readonly string m_Name;
24
25 private readonly Lazy<BadObjectReference> m_NameReference;
26 private readonly BadScope m_Scope;
27 private readonly Lazy<BadObjectReference> m_SetValueReference;
28
29 public BadMemberInfo(string name, BadScope scope)
30 {
31 m_Name = name;
32 m_Scope = scope;
33 m_NameReference = new Lazy<BadObjectReference>(() => BadObjectReference.Make("MemberInfo.Name", (p) => m_Name));
34
36 new Lazy<BadObjectReference>(() => BadObjectReference.Make("MemberInfo.GetAttributes",
37 (p) => new BadInteropFunction("GetAttributes",
39 false,
41 )
42 )
43 );
44
45 m_GetValueReference = new Lazy<BadObjectReference>(() => BadObjectReference.Make("MemberInfo.GetValue",
46 (p) => new BadInteropFunction("GetValue",
48 false,
50 )
51 )
52 );
53
54 m_SetValueReference = new Lazy<BadObjectReference>(() => BadObjectReference.Make("MemberInfo.SetValue",
55 (p) => new BadInteropFunction("SetValue",
57 false,
59 new BadFunctionParameter("value",
60 false,
61 false,
62 false,
63 null,
65 ),
66 new BadFunctionParameter("noChangeEvent",
67 true,
68 true,
69 false,
70 null,
72 )
73 )
74 )
75 );
76
78 new Lazy<BadObjectReference>(() =>
79 BadObjectReference.Make("MemberInfo.IsReadonly",
82 )
83 );
84
85 m_MemberTypeReference = new Lazy<BadObjectReference>(() => BadObjectReference.Make("MemberInfo.MemberType",
87 .Type ??
89 )
90 );
91 }
92
94
96 {
97 if (m_Scope.Attributes.TryGetValue(m_Name, out BadObject[]? attributes))
98 {
99 return new BadArray(attributes.ToList());
100 }
101
102 return new BadArray();
103 }
104
106 {
108 .Dereference(null);
109 }
110
112 {
113 if (args.Length == 1)
114 {
116 .Set(args[0], null);
117 }
118 else if (args.Length == 2)
119 {
120 if (args[1] is not IBadBoolean noEvents)
121 {
122 throw new BadRuntimeException("Second Argument must be a boolean");
123 }
124
126 .Set(args[0], null, null, noEvents.Value);
127 }
128
129 return Null;
130 }
131
132 public override bool HasProperty(string propName, BadScope? caller = null)
133 {
134 switch (propName)
135 {
136 case "Name":
137 case "GetAttributes":
138 case "GetValue":
139 case "SetValue":
140 case "IsReadonly":
141 case "MemberType":
142 return true;
143 default:
144 return base.HasProperty(propName, caller);
145 }
146 }
147
148 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
149 {
150 switch (propName)
151 {
152 case "Name":
153 return m_NameReference.Value;
154 case "GetAttributes":
155 return m_GetAttributesReference.Value;
156 case "GetValue":
157 return m_GetValueReference.Value;
158 case "SetValue":
159 return m_SetValueReference.Value;
160 case "IsReadonly":
161 return m_IsReadonlyReference.Value;
162 case "MemberType":
163 return m_MemberTypeReference.Value;
164 default:
165 return base.GetProperty(propName, caller);
166 }
167 }
168
169
171 {
172 return s_Prototype;
173 }
174
175 public override string ToSafeString(List<BadObject> done)
176 {
177 return "MemberInfo: " + m_Name;
178 }
179}
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
BadObject SetValue(BadExecutionContext ctx, BadObject[] args)
static BadClassPrototype Prototype
readonly Lazy< BadObjectReference > m_GetValueReference
readonly Lazy< BadObjectReference > m_MemberTypeReference
BadObject GetValue(BadExecutionContext ctx, BadObject[] args)
override BadClassPrototype GetPrototype()
BadMemberInfo(string name, BadScope scope)
readonly Lazy< BadObjectReference > m_IsReadonlyReference
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...
readonly Lazy< BadObjectReference > m_NameReference
override string ToSafeString(List< BadObject > done)
readonly Lazy< BadObjectReference > m_GetAttributesReference
BadObject GetAttributes(BadExecutionContext ctx, BadObject[] args)
readonly Lazy< BadObjectReference > m_SetValueReference
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
static readonly BadNativeClassPrototype< BadMemberInfo > s_Prototype
Implements the Scope for the Script Engine.
Definition BadScope.cs:16
BadObjectReference GetVariable(string name, BadScope caller)
Returns the variable reference of the specified variable.
Definition BadScope.cs:878
IReadOnlyDictionary< string, BadObject[]> Attributes
Definition BadScope.cs:126
BadPropertyInfo GetVariableInfo(string name)
Returns the variable info of the specified variable.
Definition BadScope.cs:807
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
Interop Function taking an array of arguments.
Implements a Dynamic List/Array for the BadScript Language.
Definition BadArray.cs:17
static BadClassPrototype Prototype
The Prototype for the BadScript Array.
Definition BadArray.cs:40
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
virtual BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.
Definition BadObject.cs:141
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements the base functionality for a BadScript Reference.
static BadObjectReference Make(string refText, Func< BadSourcePosition?, BadObject > getter, Action< BadObject, BadSourcePosition?, BadPropertyInfo?>? setter=null, Action< BadSourcePosition?>? delete=null)
Creates a new Reference Object.
void Set(BadObject obj, BadSourcePosition? position, BadPropertyInfo? info=null, bool noChangeEvent=false)
Sets the Referenced Object to a new Value.
bool IsReadOnly
Indicates if this property is read only.
BadClassPrototype? Type
The (optional) Type used for typechecking if a value gets assigned to this property.
The Any Prototype, Base type for all types.
static readonly BadAnyPrototype Instance
The Instance of the BadAnyPrototype.
Implements a Class Prototype for the BadScript Language.
Helper Class that Builds a Native Class from a Prototype.
static BadClassPrototype GetNative(string name)
Returns a Native Class Prototype for the given Native Type.
Implements the Interface for Native Boolean.
Definition IBadBoolean.cs:7
Contains the Error Objects for the BadScript2 Language.
Contains the Interop Function Classes for the BadScript2 Language.
Contains Runtime Function Objects.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.