BadScript 2
Loading...
Searching...
No Matches
BadInteropEnumerable.cs
Go to the documentation of this file.
1using System.Collections;
2
9
11
13{
14
15 private readonly IGrouping<BadObject, BadObject> m_Group;
16 public BadInteropGroup(IGrouping<BadObject,BadObject> enumerable) : base(enumerable)
17 {
18 m_Group = enumerable;
19 }
20
21 public override bool HasProperty(string propName, BadScope? caller = null)
22 {
23 return propName == "Key" || base.HasProperty(propName, caller);
24 }
25
26 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
27 {
28 if(propName == "Key")
29 {
30 return BadObjectReference.Make("Key", (p) => m_Group.Key);
31 }
32 return base.GetProperty(propName, caller);
33 }
34
35}
36
41{
45 private static readonly BadClassPrototype s_Prototype =
47 (_, _) => throw new BadRuntimeException("Cannot call method"),
48 () => new[]
49 {
51 .Enumerable.CreateGeneric(new[]
52 {
53 BadAnyPrototype.Instance,
54 }
55 ),
56 }
57 );
58
62 private readonly IEnumerable<BadObject> m_Enumerable;
63
67 private readonly BadFunction m_Func;
68
73 public BadInteropEnumerable(IEnumerable<BadObject> enumerable)
74 {
75 m_Enumerable = enumerable;
76
77 m_Func = new BadDynamicInteropFunction("GetEnumerator",
78 _ => new BadInteropEnumerator(m_Enumerable.GetEnumerator()),
80 {
81 BadAnyPrototype.Instance,
82 }
83 )
84 );
85 }
86
87#region IBadEnumerable Members
88
93 public IEnumerator<BadObject> GetEnumerator()
94 {
95 return m_Enumerable.GetEnumerator();
96 }
97
102 IEnumerator IEnumerable.GetEnumerator()
103 {
104 return m_Enumerable.GetEnumerator();
105 }
106
107#endregion
108
109
112 {
113 return s_Prototype;
114 }
115
117 public override bool HasProperty(string propName, BadScope? caller = null)
118 {
119 return propName == "GetEnumerator" ||
120 base.HasProperty(propName, caller);
121 }
122
124 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
125 {
126 return propName == "GetEnumerator"
127 ? BadObjectReference.Make("GetEnumerator", (p) => m_Func)
128 : base.GetProperty(propName, caller);
129 }
130
132 public override string ToSafeString(List<BadObject> done)
133 {
134 return "BadInteropEnumerable";
135 }
136}
Implements the Scope for the Script Engine.
Definition BadScope.cs:16
Implements an Interop Enumerable Object.
BadInteropEnumerable(IEnumerable< BadObject > enumerable)
Creates a new BadInteropEnumerable.
IEnumerator< BadObject > GetEnumerator()
Returns the Enumerator.
readonly IEnumerable< BadObject > m_Enumerable
The Enumerable Object.
static readonly BadClassPrototype s_Prototype
The Prototype for the Interop Enumerable Object.
readonly BadFunction m_Func
The Function that returns the Enumerator.
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
override string ToSafeString(List< BadObject > done)
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...
Implements a simple wrapper for C# IEnumerators to be used in BS2.
BadInteropGroup(IGrouping< BadObject, BadObject > enumerable)
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
readonly IGrouping< BadObject, BadObject > m_Group
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...
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
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.
Implements a function that can be called from the script.
Implements a Class Prototype for the BadScript Language.
Helper Class that Builds a Native Class from a Prototype.
static readonly BadInterfacePrototype Enumerator
The IEnumerator Interface Prototype.
BadObject CreateGeneric(BadObject[] args)
Resolves the Generic Object to a concrete type.
Defines a BadScript Enumerable.
Contains the Error Objects for the BadScript2 Language.
Contains the Interop Function Classes for the BadScript2 Language.
Contains the Interop Abstractions and Implementations for the BadScript2 Language.
Contains Runtime Function Objects.
Contains Runtime Interface Objects.
Contains the Runtime Objects.
Definition BadArray.cs:10