从对象名称获取类名称 [英] Getting class name from Object Name
问题描述
我正在用C#和ASP.net开发一个网站
我的应用程序要求从对象名称获取类名称.为了实现这一目标,
我已经使用了会话对象.该代码段如下:
Page1 ..(发送会话对象的那个)
I am developing a website in C# and ASP.net
My application demands of getting the class name from object name. For achieving this,
I have used a session object. The snippet is as follows:
Page1 .. (the one sending the session object)
clsCountryMaster obj = new clsCountryMaster();
Session["myObject"] = obj;
第2页...(接收会话对象的那一页)
Page 2 ...(the one receiving the session object)
object masterobj = Session["myObject"];
e.InputParameters.Add("masterobj", (masterobj.GetType)Context.Items["masterdata"]);
我在第2页中遇到以下错误.
找不到类型或名称空间名称"masterobj"(您是否缺少using指令或程序集引用?)
在这方面,任何机构都可以帮助我吗?
在此先感谢您.
I am getting the following error in Page 2.
The type or namespace name ''masterobj'' could not be found (are you missing a using directive or an assembly reference?)
Can any body help me in this connection?
Thanks in advance.
推荐答案
您不能执行此操作(masterobj.GetType)并进行强制转换.
您需要知道类名.
如果只需要将对象传递给另一种方法,则更简单的选择是直接使用object
类型.
e.InputParameters.Add("masterobj", (object)Context.Items["masterdata"]);
You just can''t do this (masterobj.GetType) and do a cast.
You need to know the class name.
If you just need to pass the object over to another method, an easier option for you is to use theobject
type directly.
e.InputParameters.Add("masterobj", (object)Context.Items["masterdata"]);
object masterobj =(object)Session ["myObject"];
object masterobj = (object)Session["myObject"];
这篇关于从对象名称获取类名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!