如何为名称存储在变量中的类创建对象 [英] How to create object for a class which name is stored in a variable

查看:73
本文介绍了如何为名称存储在变量中的类创建对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

在这里,我有ClassA,这是一个Class文件.我现在将此类文件名保存在数据库中.

现在,我从Db中检索ClassName.现在,我想为此类名称创建对象.有可能吗?

问候,

Anilkumar.D

Dear friends,

Here I have ClassA this is a Class file. This class file name now I am saving in Database.

Now I am retrieving the ClassName from Db. And Now I want to create the Object for this class name. Is it Possible?

Regards,

Anilkumar.D

推荐答案

尝试这些代码行
try these lines of code
string str = "System.String";

          object[] parameters = new object[] {dr7["classname"].ToString() };

          object o = System.Activator.CreateInstance(Type.GetType(str),parameters);


createinstance()


这篇关于如何为名称存储在变量中的类创建对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆