BadScript 2
Loading...
Searching...
No Matches
BadVersion.cs
Go to the documentation of this file.
7
12
17{
21 public static readonly BadClassPrototype
23
27 private static readonly BadClassPrototype s_Prototype;
28
33
37 private readonly Version m_Version;
38
43
48 public BadVersion(Version version)
49 {
50 m_Version = version;
51
52 m_ChangeVersion = BadObjectReference.Make("Version.ChangeVersion",
53 (p) => new BadDynamicInteropFunction<string>("ChangeVersion",
54 (_, s) => new BadVersion(m_Version.ChangeVersion(s)),
56 )
57 );
58 }
59
60#region IBadNative Members
61
67 public bool Equals(IBadNative other)
68 {
69 return other is BadVersion v && m_Version.Equals(v.m_Version);
70 }
71
73 public object Value => m_Version;
74
76 public Type Type => typeof(Version);
77
78#endregion
79
80
82 public override bool HasProperty(string propName, BadScope? caller = null)
83 {
84 return propName is "Major" or "Minor" or "Build" or "Revision" ||
85 base.HasProperty(propName, caller);
86 }
87
89 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
90 {
91 return propName switch
92 {
93 "Major" => BadObjectReference.Make("Version.Major", (p) => m_Version.Major),
94 "Minor" => BadObjectReference.Make("Version.Minor", (p) => m_Version.Minor),
95 "Build" => BadObjectReference.Make("Version.Build", (p) => m_Version.Build),
96 "Revision" => BadObjectReference.Make("Version.Revision", (p) => m_Version.Revision),
97 "ChangeVersion" => m_ChangeVersion,
98 _ => base.GetProperty(propName, caller),
99 };
100 }
101
104 {
105 return s_Prototype;
106 }
107
116 {
117 switch (args.Length)
118 {
119 case 0:
120 return new BadVersion(new Version());
121 case 1:
122 return args[0] is IBadString str
123 ? new BadVersion(new Version(str.Value))
124 : throw BadRuntimeException.Create(ctx.Scope,
125 "Version Constructor expects string as argument"
126 );
127 case >= 2:
128 {
129 if (args[0] is not IBadNumber major)
130 {
131 throw BadRuntimeException.Create(ctx.Scope, "Expected major version to be a number");
132 }
133
134 if (args[1] is not IBadNumber minor)
135 {
136 throw BadRuntimeException.Create(ctx.Scope, "Expected minor version to be a number");
137 }
138
139 if (args.Length == 2)
140 {
141 return new BadVersion(new Version((int)major.Value, (int)minor.Value));
142 }
143
144 if (args[2] is not IBadNumber build)
145 {
146 throw BadRuntimeException.Create(ctx.Scope, "Expected build version to be a number");
147 }
148
149 if (args.Length == 3)
150 {
151 return new BadVersion(new Version((int)major.Value, (int)minor.Value, (int)build.Value));
152 }
153
154 if (args[3] is not IBadNumber revision)
155 {
156 throw BadRuntimeException.Create(ctx.Scope, "Expected revision version to be a number");
157 }
158
159 if (args.Length == 4)
160 {
161 return new BadVersion(new Version((int)major.Value,
162 (int)minor.Value,
163 (int)build.Value,
164 (int)revision.Value
165 )
166 );
167 }
168
169 break;
170 }
171 }
172
173 throw BadRuntimeException.Create(ctx.Scope, "Invalid Argument Count for Version Constructor");
174 }
175
177 public override string ToSafeString(List<BadObject> done)
178 {
179 return m_Version.ToString();
180 }
181}
static readonly BadClassPrototype s_Prototype
The Version Class Prototype.
Definition BadVersion.cs:27
readonly Version m_Version
The Inner Version Object.
Definition BadVersion.cs:37
bool Equals(IBadNative other)
Checks if the Version is equal to another Version.
Definition BadVersion.cs:67
static readonly BadClassPrototype Prototype
The Version Class Prototype.
Definition BadVersion.cs:22
override BadClassPrototype GetPrototype()
readonly BadObjectReference m_ChangeVersion
The Change Version Function Reference.
Definition BadVersion.cs:32
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
Definition BadVersion.cs:89
BadVersion(Version version)
Creates a new Version Object.
Definition BadVersion.cs:48
object Value
The Value of the Native Object.
Definition BadVersion.cs:73
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...
Definition BadVersion.cs:82
static BadObject VersionCtor(BadExecutionContext ctx, BadObject[] args)
The Version Constructor.
Type Type
The Type of the Native Object.
Definition BadVersion.cs:76
The Execution Context. Every execution of a script needs a context the script is running in....
BadScope Scope
The Root Scope of the Context.
Implements the Scope for the Script Engine.
Definition BadScope.cs:16
static BadRuntimeException Create(BadScope? scope, string message)
Creates a new BadScriptException.
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 Class Prototype for the BadScript Language.
Defines properties for Native Types.
Definition IBadNative.cs:7
Implements the Interface for Native Numbers.
Definition IBadNumber.cs:7
Implements the Interface for Native Strings.
Definition IBadString.cs:7
Contains Versioning Extensions and APIs for the BadScript2 Runtime.
Definition BadVersion.cs:11
Contains the Error Objects for the BadScript2 Language.
Contains the Interop Function Classes for the BadScript2 Language.
Contains the Native Runtime Objects.
Definition BadBoolean.cs:6
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains the Runtime Implementation.