Skip to content

Conversation

@cdonnellytx
Copy link
Contributor

@cdonnellytx cdonnellytx commented Nov 25, 2025

This introduces a breaking change that moves the Check.Contains(string, string, System.StringComparison) extension method into the Light.GuardClauses.FrameworkExtensions namespace and a new StringExtensions class so it is no longer automatically imported with the top-level Light.GuardClauses namespace.

The reason for doing this is that not doing so conflicts with other polyfill libraries, such as Polyfill.

Basically any file that includes both namespaces and calls string.Contains(string, System.StringComparison) will fail to build in .NET Framework targets with error CS0121.

using System;
using Light.GuardClauses;
using Polyfill;

public static class MyClass
{
    public static bool DoSomething(string input)
    {
        input.MustNotBeNullOrEmpty();
        return input.Contains("x", StringComparison.OrdinalIgnoreCase); // CS0121: The call is ambiguous between the following methods or properties: 'Polyfills.Polyfill.Contains(string, string, System.StringComparison)' and 'Light.GuardClauses.Check.Contains(string, string, System.StringComparison)'
    }
}
MyClass.cs(10,22): error CS0121: The call is ambiguous between the following methods or properties: 'Polyfills.Polyfill.Contains(string, string, System.StringComparison)' and 'Light.GuardClauses.Check.Contains(string, string, System.StringComparison)'

Moving it to the FrameworkExtensions namespace allows it to not only continue to be used by Light.GuardClauses itself (both in package and source references), but also continues to expose the extension method in some way for callers looking for just this polyfill and not a larger suite of polyfills such as PolyfillLib.

The files moved need to live in the Light.GuardClauses.FrameworkExtensions namespace, and not the standard Light.GuardClauses namespace.

This is so other polyfill libraries like https://github.com/SimonCropp/Polyfill can be used with Light.GuardClauses and not create conflicts.
This modifies the Contains extension methods to move it to a new namespace.

Note this commit is separate from the rename operation in order to minimize the chance that Git loses file history tracking.
Copy link
Owner

@feO2x feO2x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting scenario I never thought about. I'm fine with this breaking change - will release version 14.0.0 of Light.GuardClauses soon.

Thank you for your contribution 🤗

@feO2x feO2x merged commit fac1d6b into feO2x:dev Nov 26, 2025
1 check passed
@feO2x
Copy link
Owner

feO2x commented Nov 26, 2025

I've just release Light.GuardClauses 14.0.0! Thanks again for your commitment!

@cdonnellytx cdonnellytx deleted the feature/playNiceWithPolyfillLib branch November 26, 2025 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants