BadScript 2
Loading...
Searching...
No Matches
BadClassPrototype.cs
Go to the documentation of this file.
4
6
10public abstract class BadClassPrototype : BadObject
11{
16 "Type",
17 (_, _) => throw new BadRuntimeException("Classes cannot be extended")
18 );
19
23 protected abstract BadClassPrototype? BaseClass { get; }
24
25
29 public readonly BadMetaData MetaData;
30
38 string name,
39 BadMetaData? metaData)
40 {
41 Name = name;
42 MetaData = metaData ?? BadMetaData.Empty;
43 }
44
48 public abstract bool IsAbstract { get; }
49
53 public abstract IReadOnlyCollection<BadInterfacePrototype> Interfaces { get; }
54
58 public string Name { get; }
59
65 {
66 return BaseClass;
67 }
68
71 {
72 return Prototype;
73 }
74
84 public abstract IEnumerable<BadObject> CreateInstance(BadExecutionContext caller, bool setThis = true);
85
91 public virtual bool IsSuperClassOf(BadClassPrototype proto)
92 {
93 if (proto == this)
94 {
95 return true;
96 }
97
98 bool isBaseSuper = proto.BaseClass != null && IsSuperClassOf(proto.BaseClass);
99
100 return isBaseSuper;
101 }
102
108 public virtual bool IsAssignableFrom(BadObject obj)
109 {
110 if (obj == Null)
111 {
112 return true;
113 }
114
115 if (obj is BadClass cls)
116 {
117 return cls.InheritsFrom(this);
118 }
119
120 BadClassPrototype type = obj.GetPrototype();
121
122 return IsSuperClassOf(type);
123 }
124
125
127 public override string ToSafeString(List<BadObject> done)
128 {
129 return $"class {Name}";
130 }
131}
Implements a Meta Data container for an expression.
static readonly BadMetaData Empty
An empty Meta Data object.
The Execution Context. Every execution of a script needs a context the script is running in....
The Base Class for all BadScript Objects.
Definition BadObject.cs:14
BadClassPrototype GetPrototype()
Returns the Prototype of this Object.
static readonly BadObject Null
The Null Value for the BadScript Language.
Definition BadObject.cs:28
Implements a Type Instance in the BadScript Language.
Definition BadClass.cs:11
Implements a Class Prototype for the BadScript Language.
IReadOnlyCollection< BadInterfacePrototype > Interfaces
The Implemented Interfaces.
virtual bool IsAssignableFrom(BadObject obj)
Returns true if the provided object is an instance of this class or a subclass of this class.
static readonly BadClassPrototype Prototype
The Prototype of the ClassPrototype(can not be used)
bool IsAbstract
Indicates if the Class is Abstract(e.g. can not be instantiated)
BadClassPrototype(string name, BadMetaData? metaData)
Creates a new Class Prototype.
override string ToSafeString(List< BadObject > done)
virtual bool IsSuperClassOf(BadClassPrototype proto)
Returns true if the Class is a Subclass of the given Class.
readonly BadMetaData MetaData
The Metadata of the Class.
BadClassPrototype? GetBaseClass()
Returns the base class.
BadClassPrototype? BaseClass
The Base Class of the Prototype.
IEnumerable< BadObject > CreateInstance(BadExecutionContext caller, bool setThis=true)
Creates an Instance of the Class.
Contains the Parser for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains Runtime Interface Objects.