BadScript 2
Loading...
Searching...
No Matches
BadVersion.cs
Go to the documentation of this file.
8
13
18{
22 public static readonly BadClassPrototype
24 null);
25
29 private static readonly BadClassPrototype s_Prototype;
30
35
39 private readonly Version m_Version;
40
41 static BadVersion()
42 {
44 null);
45 }
46
51 public BadVersion(Version version)
52 {
53 m_Version = version;
54
55 m_ChangeVersion = BadObjectReference.Make("Version.ChangeVersion",
56 (p) => new BadDynamicInteropFunction<string>("ChangeVersion",
57 (_, s) => new BadVersion(m_Version.ChangeVersion(s)),
59 new BadFunctionParameter("changeFormat", false, true, false, null, BadNativeClassBuilder.GetNative("string"))
60 )
61 );
62 }
63
64#region IBadNative Members
65
71 public bool Equals(IBadNative other)
72 {
73 return other is BadVersion v && m_Version.Equals(v.m_Version);
74 }
75
77 public object Value => m_Version;
78
80 public Type Type => typeof(Version);
81
82#endregion
83
84
86 public override bool HasProperty(string propName, BadScope? caller = null)
87 {
88 return propName is "Major" or "Minor" or "Build" or "Revision" or "ChangeVersion" ||
89 base.HasProperty(propName, caller);
90 }
91
93 public override BadObjectReference GetProperty(string propName, BadScope? caller = null)
94 {
95 return propName switch
96 {
97 "Major" => BadObjectReference.Make("Version.Major", (p) => m_Version.Major),
98 "Minor" => BadObjectReference.Make("Version.Minor", (p) => m_Version.Minor),
99 "Build" => BadObjectReference.Make("Version.Build", (p) => m_Version.Build),
100 "Revision" => BadObjectReference.Make("Version.Revision", (p) => m_Version.Revision),
101 "ChangeVersion" => m_ChangeVersion,
102 _ => base.GetProperty(propName, caller),
103 };
104 }
105
108 {
109 return s_Prototype;
110 }
111
120 {
121 switch (args.Length)
122 {
123 case 0:
124 return new BadVersion(new Version());
125 case 1:
126 return args[0] is IBadString str
127 ? new BadVersion(new Version(str.Value))
128 : throw BadRuntimeException.Create(ctx.Scope,
129 "Version Constructor expects string as argument"
130 );
131 case >= 2:
132 {
133 if (args[0] is not IBadNumber major)
134 {
135 throw BadRuntimeException.Create(ctx.Scope, "Expected major version to be a number");
136 }
137
138 if (args[1] is not IBadNumber minor)
139 {
140 throw BadRuntimeException.Create(ctx.Scope, "Expected minor version to be a number");
141 }
142
143 if (args.Length == 2)
144 {
145 return new BadVersion(new Version((int)major.Value, (int)minor.Value));
146 }
147
148 if (args[2] is not IBadNumber build)
149 {
150 throw BadRuntimeException.Create(ctx.Scope, "Expected build version to be a number");
151 }
152
153 if (args.Length == 3)
154 {
155 return new BadVersion(new Version((int)major.Value, (int)minor.Value, (int)build.Value));
156 }
157
158 if (args[3] is not IBadNumber revision)
159 {
160 throw BadRuntimeException.Create(ctx.Scope, "Expected revision version to be a number");
161 }
162
163 if (args.Length == 4)
164 {
165 return new BadVersion(new Version((int)major.Value,
166 (int)minor.Value,
167 (int)build.Value,
168 (int)revision.Value
169 )
170 );
171 }
172
173 break;
174 }
175 }
176
177 throw BadRuntimeException.Create(ctx.Scope, "Invalid Argument Count for Version Constructor");
178 }
179
181 public override string ToSafeString(List<BadObject> done)
182 {
183 return m_Version.ToString();
184 }
185}
static readonly BadClassPrototype s_Prototype
The Version Class Prototype.
Definition BadVersion.cs:29
readonly Version m_Version
The Inner Version Object.
Definition BadVersion.cs:39
bool Equals(IBadNative other)
Checks if the Version is equal to another Version.
Definition BadVersion.cs:71
static readonly BadClassPrototype Prototype
The Version Class Prototype.
Definition BadVersion.cs:23
override BadClassPrototype GetPrototype()
readonly BadObjectReference m_ChangeVersion
The Change Version Function Reference.
Definition BadVersion.cs:34
override BadObjectReference GetProperty(string propName, BadScope? caller=null)
Returns a Reference to the Property with the given Name.The Property Reference
Definition BadVersion.cs:93
BadVersion(Version version)
Creates a new Version Object.
Definition BadVersion.cs:51
object Value
The Value of the Native Object.
Definition BadVersion.cs:77
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:86
static BadObject VersionCtor(BadExecutionContext ctx, BadObject[] args)
The Version Constructor.
Type Type
The Type of the Native Object.
Definition BadVersion.cs:80
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.
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.
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:12
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.