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(
46 this BadClass instance,
47 IEnumerable<BadInterfacePrototype> interfaces)
48 {
49 List<BadInterfaceValidatorError> errors = new List<BadInterfaceValidatorError>();
50
51 BadInterfaceConstraint[] allConstraints = interfaces
52 .SelectMany(x => x.GetAllInterfaces())
53 .Distinct()
54 .SelectMany(x => x.Constraints)
55 .ToArray();
56
57 foreach (BadInterfaceConstraint constraint in allConstraints)
58 {
59 constraint.Validate(instance, errors);
60 }
61
62 return new BadInterfaceValidatorResult(errors.ToArray());
63 }
64}
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.