Is there a way to apply c# generic constraints severally rather than jointly? -


There is a way to implement many different csharp generic barriers of the same type where the test is and instead ?

I have an extension method that I want to apply to a subset of an interface, but there is no general interface or base class which captures only those classes that I want to target.

In the example below, I can write several ways with the same constraint which all call the same floating method, but I am thinking that writing a method with many non-intersecting obstacles There is no way

Example

  Interface IAnimal {bool IsWet {get; Set; } Bool isDrowned {get; Set; }} Public static class SwimmerHelpers [/ * This is the psuedo effect of what I want to achieve * Public / static void & lt; T & gt; (The T-PashootsSwim) where T: IAnimal, human | Where t: ienail, fish | Where T: IAnimal, Whale ....}  

With the actual realm of FYI I am the HTML element that all implement an IElement interface, but I only target the elements Where some behaviors are valid in the HTML specification and no specific specific interface is implemented by them such as elements which can be a readable feature.

The reason for this work is not understood when you consider the fact that your There are no general barriers to implementing the desired use; instead, they allow you to make some assumptions about the parameters there. For example, by blocking the type to be IComparable , you know that you can call the compare method even if the exact type is not yet known new A type of prevention with () ensures that you can call a default constructor call on the type. So if the general obstacles have allowed you to specify an obstacle or some other, then you can not make those assumptions.


Comments