public static void Requires( bool condition, string userMessage = null, [CallerFilePath] string path = "", [CallerLineNumber] int lineNumber = 0) { if (!condition) { ContractRuntimeHelper.ReportFailure(ContractFailureKind.Precondition, userMessage, null, new Provenance(path, lineNumber)); } }
public static void RequiresForAll <T>( IEnumerable <T> collection, Predicate <T> predicate, string userMessage = null, [CallerFilePath] string path = "", [CallerLineNumber] int lineNumber = 0) { if (!CheckForAll(collection, predicate)) { ContractRuntimeHelper.ReportFailure(ContractFailureKind.Precondition, userMessage, null, new Provenance(path, lineNumber)); } }
public static void AssertNotNull <T>( [NotNull] T?value, string?userMessage = null, [CallerFilePath] string path = "", [CallerLineNumber] int lineNumber = 0) where T : class { if (value == null) { userMessage ??= "The value should not be null."; ContractRuntimeHelper.ReportFailure(ContractFailureKind.Assert, userMessage, null, new Provenance(path, lineNumber)); } }
public static void RequiresNotNull <T>( [NotNull] T?o, string?userMessage = null, [CallerFilePath] string path = "", [CallerLineNumber] int lineNumber = 0) where T : struct { if (o == null) { userMessage ??= "The value should not be null."; ContractRuntimeHelper.ReportFailure(ContractFailureKind.Precondition, userMessage, null, new Provenance(path, lineNumber)); } }
public static void AssertNotNullOrEmpty( [NotNull] string?o, string?userMessage = null, [CallerFilePath] string path = "", [CallerLineNumber] int lineNumber = 0) { if (string.IsNullOrEmpty(o)) { userMessage ??= "The value should not be null or empty."; ContractRuntimeHelper.ReportFailure(ContractFailureKind.Assert, userMessage, null, new Provenance(path, lineNumber)); } }
public static void RequiresNotNullOrWhiteSpace( [NotNull] string?o, string?userMessage = null, [CallerFilePath] string path = "", [CallerLineNumber] int lineNumber = 0) { if (string.IsNullOrWhiteSpace(o)) { userMessage ??= "The value should not be null or whitespace."; ContractRuntimeHelper.ReportFailure(ContractFailureKind.Precondition, userMessage, null, new Provenance(path, lineNumber)); } }
public static void AssertNotNullOrEmpty( [NotNull] string?o, string?userMessage = null, [CallerFilePath] string path = "", [CallerLineNumber] int lineNumber = 0) { if (string.IsNullOrEmpty(o)) { userMessage ??= "The value should not be null or empty."; ContractRuntimeHelper.ReportFailure(ContractFailureKind.Assert, userMessage, null, new Provenance(path, lineNumber)); } #pragma warning disable CS8777 // Parameter must have a non-null value when exiting. }
public static void Invariant( bool condition, #if NETSTANDARD2_0 [Localizable(false)] #endif string userMessage = null, [CallerFilePath] string path = "", [CallerLineNumber] int lineNumber = 0) { if (!condition) { ContractRuntimeHelper.ReportFailure(ContractFailureKind.Invariant, userMessage, null, new Provenance(path, lineNumber)); } }
public static void AssertDebug( [DoesNotReturnIf(false)] bool condition, #if NETSTANDARD2_0 [Localizable(false)] #endif string userMessage = null, [CallerFilePath] string path = null, [CallerLineNumber] int lineNumber = 0) { if (!condition) { ContractRuntimeHelper.ReportFailure(ContractFailureKind.Assert, userMessage, null, new Provenance(path, lineNumber)); } }
public static Exception AssertFailure( // Disable localization prevents CA2204 #if NETSTANDARD2_0 [Localizable(false)] #endif string message = null, [CallerFilePath] string path = null, [CallerLineNumber] int lineNumber = 0) { ContractRuntimeHelper.ReportFailure(ContractFailureKind.Assert, message, null, new Provenance(path, lineNumber)); // This method should fail regardless of the ContractFailEvent handlers. ContractRuntimeHelper.RaiseContractFailedEvent( ContractFailureKind.Assert, message, null, new Provenance(path, lineNumber), out var text); return(new ContractException(ContractFailureKind.Assert, text, message, null)); }