Dynamically create an object of

前端 未结 6 1441
时光说笑
时光说笑 2020-12-02 16:40

I have a table in my database that I use to manage relationships across my application. it\'s pretty basic in it\'s nature - parentType,parentId, childType, childId... all a

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-02 17:18

    public static T GetInstance(params object[] args)
    {
         return (T)Activator.CreateInstance(typeof(T), args);
    }
    

    I would use Activator.CreateInstance() instead of casting, as the Activator has a constructor for generics.

提交回复
热议问题