GuardClauses icon indicating copy to clipboard operation
GuardClauses copied to clipboard

Unify method signatures among frameworks

Open Ergamon opened this issue 1 year ago • 2 comments

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.

Ergamon avatar Feb 10 '24 11:02 Ergamon

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

ardalis avatar Feb 10 '24 14:02 ardalis

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.

Ergamon avatar Feb 10 '24 18:02 Ergamon

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

canro91 avatar Jul 03 '24 16:07 canro91