Setting generic type at runtime

后端 未结 6 1263
无人共我
无人共我 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:06

    You can't. Generic type identifiers have to be known at compile time.

    edit

    as of other posts, it appears to be possible by dynamicly generating the method and invoking it - which has dangers of course. See Thomas' and Dathan's posts for more inforation.

提交回复
热议问题