Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- interface IValid
- {
- bool IsValid();
- }
- public abstract class BaseClass : IValid
- {
- public bool Validity { get; protected set; } = true;
- public bool IsValid()
- {
- return this.Validity;
- }
- }
- public class ChildOfTrue : BaseClass
- {
- public ChildOfTrue() => this.Validity = true;
- }
- public class ChildOfFalse : BaseClass
- {
- public ChildOfFalse() => this.Validity = false;
- }
- public class TestCase
- {
- public TestCase()
- {
- List<BaseClass> testSubjects = new List<BaseClass>
- {
- new ChildOfTrue(),
- new ChildOfFalse(),
- null
- };
- foreach (var testSubject in testSubjects)
- {
- if (testSubject != null && testSubject.IsValid())
- {
- /* Perform tests. */
- }
- }
- }
- }
- public static class BaseClassExtensionHelper
- {
- public static bool IsValid(this BaseClass o)
- {
- if (ReferenceEquals(o, null)) return false;
- return o.Validity;
- }
- public static bool IsNotNullAndValid(this BaseClass o)
- {
- if (ReferenceEquals(o, null)) return false;
- return o.IsValid();
- }
- }
- if (BaseClassExtensionHelper.IsValid(testSubject)) { /* Perform tests. */ }
Add Comment
Please, Sign In to add comment