# Custom matchers

When defining argument expectations, developers can use It.Is to apply custom predicates to incoming parameters.

```csharp
mock.Verify(p => p.DoSomething(It.Is<string>(s => s.Length > 100)));
```

Over time, developers might want to collect these custom expressions into a library. Unfortunately, the matching expressions can't be extracted as they are because `It.Is<T>` accepts an `Expression<Func<T, bool>>` instead of a simple `Func<T, bool>` delegate.

To support this use case, Moq gives developers the possibility to create **custom matchers**. A custom matcher is an expression that wraps a delegate so that it can be used when defining an argument expectation.

```csharp
public static class ParameterExpectations
{
    [Matcher]
    public static string StringLongerThan(int size) => Moq.Match.Create<string>(s => s.Length > size);
}

mock.Verify(p => p.DoSomething(ParameterExpectations.StringLongerThan(100)));
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.educationsmediagroup.com/unit-testing-csharp/moq/custom-matchers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
