| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="ValidationExtensions.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using MyNet.Observable.Behaviors; |
| | | 8 | | |
| | | 9 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 10 | | namespace MyNet.Observable; |
| | | 11 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 12 | | |
| | | 13 | | public static class ValidationExtensions |
| | | 14 | | { |
| | | 15 | | extension(ObservableObject owner) |
| | | 16 | | { |
| | | 17 | | /// <summary> |
| | | 18 | | /// Validates the current state of the object by checking if it implements the IValidationBehavior behavior and |
| | | 19 | | /// </summary> |
| | | 20 | | /// <returns>True if the object is valid; otherwise, false.</returns> |
| | 27 | 21 | | public bool Validate() => owner.Behaviors.TryGet<IValidationBehavior>(out var behavior) && behavior.Validate(); |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Validates the current state of the object by traversing its behavior graph and checking if any behavior in t |
| | | 25 | | /// </summary> |
| | | 26 | | /// <returns>True if all behaviors in the graph are valid; otherwise, false.</returns> |
| | 0 | 27 | | public bool ValidateGraph() => ValidationGraphVisitor.Validate(owner); |
| | | 28 | | } |
| | | 29 | | } |
| | | 30 | | |