Setting generic type at runtime

后端 未结 6 1262
无人共我
无人共我 2020-11-27 18:24

I have a class

public class A
{
   public static string B(T obj)
   {
       return TransformThisObjectToAString(obj);
   }
}

The

6条回答
  •  情话喂你
    2020-11-27 19:03

    Trying to substitute type parameter at runtime will defeat the whole purpose of type saftey , which is enforced by C# compiler.C# compiler make sures that type parameter are specified at compile time and there is no ambiguity on type arguments at runtime.I doubt you can substitue type parameter at runtime in Generic Type.Specifying type argument of type "Type" is almost like having an unbound generic type.

提交回复
热议问题