TL DR
I would like this to compile in C #
public void some_method< T >() where T : class1, class2
Is it possible?
Full context
I have two methods that are identical except for parameter one .
public SignInResponseMessage Generate(SignInRequestMessage request, (X509Certificate2 || WindowsPrincipal) principal, Uri requestUri) { SignInResponseMessage response = null; ClaimsIdentity identity = null; if (principal != null) { identity = CreateSubject(principal); response = Generate(request, requestUri, identity); } else { throw new ArgumentNullException("principal"); } return response; }
I am currently replicating this method and it makes me cringe a bit inside since I really would like to make this DRY
-er. Looking around, this documentation seemed promising, but it only allows me to add one class restriction. I get the following error in the second class:
Mistake 1 A class type restriction of 'class2' should appear before any other restrictions
If WindowsPrincipal
and X509Certificate2
were the two classes that I wrote, I could easily get them to implement the same interface, and it would be nice to go, but this is not an option.
Is there a way to accomplish what I would like to do?
If not, I would like to know more about the basic mechanism that makes this impossible .
source share