ardalis / GuardClauses

A simple package with guard clause extensions.
MIT License
3.06k stars 270 forks source link

Unify method signatures among frameworks #337

Closed Ergamon closed 3 months ago

Ergamon commented 8 months ago

I am in the process of looking for a nice guard clause library using the newer feature of CallerArgumentExpressionAttribute. It almost seemed I found it here. When I did my first tests on our current .NET 8 environment it looked perfect.

But today I started exchanging our old library with this one in one of our older solutions. Sadly for some reasons we cannot move this one away from .NET Framework. To my surprise suddenly all method signatures looked different.

My goal for our team is always to keep the differences among the solutions as small as possible. So a Guard Clause library working different is a no go.

Is there any particular reason why you are holding back this feature?

I mean all you have to do is add this to your project:

#if NETFRAMEWORK || NETSTANDARD2_0
namespace System.Runtime.CompilerServices
{
  [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
  internal sealed class CallerArgumentExpressionAttribute : Attribute
  {
    public CallerArgumentExpressionAttribute(string parameterName)
    {
      ParameterName = parameterName;
    }

    public string ParameterName { get; }
  }
}
#endif

and voila it works on older platforms.

ardalis commented 8 months ago

Sounds like a great idea! Are you looking to add a pull request?

Ergamon commented 8 months ago

Done. I created one.

If you accept it, there is then the question, if it is worth to have a special netstandard 2.1 version. As every .net version that can use 2.1 also can use 2.0. But I did not want to make more changes then necessary in a single pull request.

canro91 commented 3 months ago

@ardalis I think we can close this one. Addressed on #338