Call Regex.IsMatch when Match is not needed (#903)

This commit is contained in:
Stephen Halter 2025-10-20 14:05:50 -05:00 • committed by GitHub
commit b575f6e52e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -317,15 +317,21 @@ internal sealed class AIFunctionMcpServerResource : McpServerResource
public override bool IsMatch(string uri)
{
Throw.IfNull(uri);
return TryMatch(uri, out _);
}
private bool TryMatch(string uri, out Match? match)
{
// For templates, use the Regex to parse. For static resources, we can just compare the URIs.
if (_uriParser is null)
{
// This resource is not templated.
return UriTemplate.UriTemplateComparer.Instance.Equals(uri, ProtocolResourceTemplate.UriTemplate);
}
return _uriParser.IsMatch(uri);
}
private bool TryMatch(string uri, out Match? match)
{
if (_uriParser is null)
{
match = null;
return UriTemplate.UriTemplateComparer.Instance.Equals(uri, ProtocolResourceTemplate.UriTemplate);
}