BadScript 2
Loading...
Searching...
No Matches
BadInterfacePropertyConstraint.cs
Go to the documentation of this file.
6
8
10{
14 private readonly BadClassPrototype? m_Prototype;
15
19 public readonly string Name;
20
24 public readonly BadExpression? Type;
25
32 {
33 Name = name;
34 Type = type;
35 }
36
43 public BadInterfacePropertyConstraint(string name, BadExpression? type, BadClassPrototype? prototype)
44 {
45 Name = name;
46 Type = type;
47 m_Prototype = prototype;
48 }
49
51 public override void Validate(BadClass obj, List<BadInterfaceValidatorError> errors)
52 {
53 if (Type != null && m_Prototype == null)
54 {
55 throw new BadRuntimeException("Type was not Evaluated.");
56 }
57
58 if (!obj.HasProperty(Name, obj.Scope))
59 {
60 errors.Add(new BadInterfaceValidatorError($"Missing Property. Expected {Name}", this));
61
62 return;
63 }
64
66 BadClassPrototype actual = info.Type ?? BadAnyPrototype.Instance;
68 if (expected == BadVoidPrototype.Instance)
69 {
70 errors.Add(new BadInterfaceValidatorError("Interface Properties can not be of type 'void'", this));
71 }
72 if (!expected.IsSuperClassOf(actual))
73 {
74 errors.Add(new BadInterfaceValidatorError($"Property Type Mismatch. Expected {expected} but got {actual}", this));
75 }
76 }
77
78 public override bool Equals(BadInterfaceConstraint? other)
79 {
80 return other is BadInterfacePropertyConstraint c && c.Name == Name && c.Type == Type;
81 }
82
83 protected override int GetConstraintHash()
84 {
85 return BadHashCode.Combine(Name, Type, typeof(BadInterfacePropertyConstraint));
86 }
87}
Base Implementation for all Expressions used inside the Script.
BadInterfacePropertyConstraint(string name, BadExpression? type, BadClassPrototype? prototype)
Creates a new Property Constraint.
BadInterfacePropertyConstraint(string name, BadExpression? type)
Creates a new Property Constraint.
override void Validate(BadClass obj, List< BadInterfaceValidatorError > errors)
BadPropertyInfo GetVariableInfo(string name)
Returns the variable info of the specified variable.
Definition BadScope.cs:946
Stores Meta Information about a Property.
The Any Prototype, Base type for all types.
static readonly BadAnyPrototype Instance
The Instance of the BadAnyPrototype.
Implements a Type Instance in the BadScript Language.
Definition BadClass.cs:11
BadScope Scope
Table of all members of this type(excluding base class members)
Definition BadClass.cs:35
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 BadClass.cs:92
Implements a Class Prototype for the BadScript Language.
virtual bool IsSuperClassOf(BadClassPrototype proto)
Returns true if the Class is a Subclass of the given Class.
The Void Prototype, can be assigned to nothing, can not be inherited from, can not be instantiated....
static BadVoidPrototype Instance
The Instance of the BadVoidPrototype.
Implements Combination of HashCode Functions Taken from decompiled source of System....
Contains the Type Expressions for the BadScript2 Language.
Contains the Error Objects for the BadScript2 Language.
Contains Runtime Interface Objects.
Contains the Runtime Objects.
Definition BadArray.cs:10
Contains Utility Functions and Classes.
Definition BadEnum.cs:5