Is there a way to declare a generic function that the generic type is of type1 or type2?
example:
public void Foo(T number) { }
No.
That doesn't make sense; T would not have any usable compile-time type in the method.
T
Instead, you should make two overloaded methods.