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;
52 "Version.ChangeVersion",
54 "ChangeVersion",
55 (_, s) => new BadVersion(m_Version.ChangeVersion(s)),
57 )
58 );
59 }
60
66 public bool Equals(IBadNative other)
67 {
68 return other is BadVersion v && m_Version.Equals(v.m_Version);
69 }
70
72 public object Value => m_Version;
73
75 public Type Type => typeof(Version);
76
77
79 public override bool HasProperty(string propName, BadScope? caller = null)
80 {
81 return propName is "Major" or "Minor" or "Build" or "Revision" ||
82 base.HasProperty(propName, caller);
83 }
84
86 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
87 {
88 return propName switch
89 {
90 "Major" => BadObjectReference.Make("Version.Major", () => m_Version.Major),
91 "Minor" => BadObjectReference.Make("Version.Minor", () => m_Version.Minor),
92 "Build" => BadObjectReference.Make("Version.Build", () => m_Version.Build),
93 "Revision" => BadObjectReference.Make("Version.Revision", () => m_Version.Revision),
94 "ChangeVersion" => m_ChangeVersion,
95 _ => base.GetProperty(propName, caller),
96 };
97 }
98
101 {
102 return s_Prototype;
103 }
104
113 {
114 switch (args.Length)
115 {
116 case 0:
117 return new BadVersion(new Version());
118 case 1:
119 return args[0] is IBadString str
120 ? new BadVersion(new Version(str.Value))
121 : throw BadRuntimeException.Create(ctx.Scope, "Version Constructor expects string as argument");
122 case >= 2:
123 {
124 if (args[0] is not IBadNumber major)
125 {
126 throw BadRuntimeException.Create(ctx.Scope, "Expected major version to be a number");
127 }
128
129 if (args[1] is not IBadNumber minor)
130 {
131 throw BadRuntimeException.Create(ctx.Scope, "Expected minor version to be a number");
132 }
133
134 if (args.Length == 2)
135 {
136 return new BadVersion(new Version((int)major.Value, (int)minor.Value));
137 }
138
139 if (args[2] is not IBadNumber build)
140 {
141 throw BadRuntimeException.Create(ctx.Scope, "Expected build version to be a number");
142 }
143
144 if (args.Length == 3)
145 {
146 return new BadVersion(new Version((int)major.Value, (int)minor.Value, (int)build.Value));
147 }
148
149 if (args[3] is not IBadNumber revision)
150 {
151 throw BadRuntimeException.Create(ctx.Scope, "Expected revision version to be a number");
152 }
153
154 if (args.Length == 4)
155 {
156 return new BadVersion(
157 new Version(
158 (int)major.Value,
159 (int)minor.Value,
160 (int)build.Value,
161 (int)revision.Value
162 )
163 );
164 }
165
166 break;
167 }
168 }
169
170 throw BadRuntimeException.Create(ctx.Scope, "Invalid Argument Count for Version Constructor");
171 }
172
174 public override string ToSafeString(List<BadObject> done)
175 {
176 return m_Version.ToString();
177 }
178}
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:66
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:86
BadVersion(Version version)
Creates a new Version Object.
Definition BadVersion.cs:48
object Value
The Value of the Native Object.
Definition BadVersion.cs:72
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:79
static BadObject VersionCtor(BadExecutionContext ctx, BadObject[] args)
The Version Constructor.
Type Type
The Type of the Native Object.
Definition BadVersion.cs:75
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:238
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:129
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.
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.