using System; namespace Roadie.Library.Utility { public static class SimpleContract { /// /// Test that Predicate is True if not then throw Exception /// /// Exception Type To Throw /// Predicate to Test (Must Test True) /// Message For Exception public static void Requires(bool Predicate, string Message) where TException : Exception, new() { if (!Predicate) { var ex = new TException(); // I could not figure out how to set message on a generic Error so I pushed it to Data with Predicate Result as Key ex.Data.Add(Predicate.ToString(), Message); throw ex; } } /// /// Test that Predicate is True if not then throw Exception /// /// Predicate to Test (Must Test True) /// Message For Exception public static void Requires(bool Predicate, string Message) { if (!Predicate) { throw new Exception(Message); } } } }