I have a class :
class MyClass
{
public static class MyNestedClass
{
public const int M1 = 1;
public const int M2 = 2;
}
}
class MyClass2
{
public static class MyNestedClass
{
public const int M1 = 1;
public const int M2 = 2;
}
}
and a generic function :
private static void Work<T>()
{
Type myType = typeof(T.MyNestedClass);
myType.GetFields().Select(....);
// .. use T here as well..
}
I get error : error CS0704: Cannot do member lookup in 'T' because it is a type parameter
.
Since MyNestedClass
is static class, when i try to pass it as another Generic Type argument as :
private static void Work<T, S>()
{
Type myType = typeof(S);
myType.GetFields().Select(....);
// .. use T here as well..
}
calling via,
Work<MyClass, MyClass.MyNestedClass>();
gives me error : static types cannot be used as type arguments
What is the right way to access nested static and non-static class in c# ?