BadScript 2
Loading...
Searching...
No Matches
BadInterfaceTools.cs
Go to the documentation of this file.
2
6public static class BadInterfaceTools
7{
13 public static IEnumerable<BadInterfacePrototype> GetAllInterfaces(this BadClassPrototype type)
14 {
15 if (type is BadInterfacePrototype interfacePrototype)
16 {
17 yield return interfacePrototype;
18 }
19
20 BadClassPrototype? baseClass = type.GetBaseClass();
21
22 if (baseClass != null)
23 {
24 foreach (BadInterfacePrototype i in baseClass.GetAllInterfaces())
25 {
26 yield return i;
27 }
28 }
29
30 foreach (BadInterfacePrototype? i in type.Interfaces)
31 {
32 foreach (BadInterfacePrototype x in i.GetAllInterfaces())
33 {
34 yield return x;
35 }
36 }
37 }
38
45 public static BadInterfaceValidatorResult Validate(this BadClass instance,
46 IEnumerable<BadInterfacePrototype> interfaces)
47 {
48 List<BadInterfaceValidatorError> errors = new List<BadInterfaceValidatorError>();
49
50 BadInterfaceConstraint[] allConstraints = interfaces
51 .SelectMany(x => x.GetAllInterfaces())
52 .Distinct()
53 .SelectMany(x => x.Constraints)
54 .ToArray();
55
56 foreach (BadInterfaceConstraint constraint in allConstraints)
57 {
58 constraint.Validate(instance, errors);
59 }
60
61 return new BadInterfaceValidatorResult(errors.ToArray());
62 }
63}
Implements a Type Instance in the BadScript Language.
Definition BadClass.cs:11
Implements a Class Prototype for the BadScript Language.
BadClassPrototype? GetBaseClass()
Returns the base class.
void Validate(BadClass obj, List< BadInterfaceValidatorError > errors)
Validates the given Object against this Constraint.
override IReadOnlyCollection< BadInterfacePrototype > Interfaces
static IEnumerable< BadInterfacePrototype > GetAllInterfaces(this BadClassPrototype type)
Returns all Interfaces implemented by this Type.
static BadInterfaceValidatorResult Validate(this BadClass instance, IEnumerable< BadInterfacePrototype > interfaces)
Validates a given Object against a set of Interfaces.
Contains Runtime Interface Objects.