diff --git a/ContractExtensions/ContractsEx/Assertions/Messages/MessageExtensions.cs b/ContractExtensions/ContractsEx/Assertions/Messages/MessageExtensions.cs index 29d72ef..9a1a494 100644 --- a/ContractExtensions/ContractsEx/Assertions/Messages/MessageExtensions.cs +++ b/ContractExtensions/ContractsEx/Assertions/Messages/MessageExtensions.cs @@ -45,11 +45,22 @@ public static bool IsValidForRequires(this Message message) return Match(message, _ => true, // string literals are valid r => IsValidReference(r.Reference), // references should be checked separately - _ => false, // message calls are invalid + i => IsValidInvocation(i.InvocationExpression), // message calls are invalid () => true); // "NoMessage" is valid } + private static bool IsValidInvocation(IInvocationExpression invocationExpression) + { + // Supper naive an hacky way of checking for nameof: + if (invocationExpression.GetText().StartsWith("nameof(", StringComparison.InvariantCulture)) + { + return true; + } + + return false; + } + /// /// Returns true if points to the static field or property /// with at least internal access.