I am using the code below. It is intended for a specific type, to limit its tooltip in intellisense, etc.
public static Generic Get<Generic>(this Entity input) { return (Generic)input; }
Now I would like to use the same Get method for another type (or, to be fully covered, several other types, but still a number of fixes). So I added a second method, and the code is as follows.
public static Generic Get<Generic>(this Entity input) { return (Generic)input; } public static Generic Get<Generic>(this Entity2 input) { return (Generic)input; }
It seems to me that the best approach would be to keep it in the same method and still cover all the types in question. Is there a syntax to include, for example, two signature signatures? Something like this pseudo code below.
public static Generic Get<Generic>(this [Entity, Entity2] input) { return (Generic)input; }
The best approach that I can think of, as shown below, consists of an input method for each type and logic in a private place. This makes sense when the logic is extensive, but looks redundant when it is only a line or two.
public static Generic Get<Generic>(this Entity input) { return CommonLogic(input); } public static Generic Get<Generic>(this Entity2 input) { return CommonLogic(input); } private static Generic CommonLogic(Object input) { return (Generic)input; }
c # extension-methods
Konrad Viltersten
source share