会员
众包
新闻
博问
闪存
云市场
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
白桦的天空
第一次的心动,永远的心痛!
首页
::
新随笔
::
联系
::
管理
公告
C#动态加载类
Posted on
2005-11-18 15:07
白桦的天空
阅读(
1028
) 评论(
0
)
编辑
收藏
举报
using
System;
using
System.Data;
using
System.Reflection;
using
System.Web;
using
System.Web.UI;
namespace
WebApplication1
{
/**/
///
<summary>
///
Class1 的摘要说明。
///
</summary>
public
class
Servlets:System.Web.UI.Page
{
private
void
Page_Load(
object
sender, System.EventArgs e)
{
//
在此处放置用户代码以初始化页面
Response.Write(InitPage());
AfterLoadPage();
//
string aliasName="test2.Class2";
//
result.AppAssembly = ((ClassItem)item).ClassAssembly;
//
return result;
//
Assembly assem= Assembly.Load(aliasName);
Type[] helloType
=
LoadAssembly(
"
test2
"
);
MethodInfo printMethod
=
helloType[
0
].GetMethod(
"
reback
"
);
Object obj
=
Activator.CreateInstance(helloType[
0
]);
Response.Write(printMethod.Invoke(obj,
null
));
//
Object[] args = new Object[1];
//
args[0] = "From CSharp Late Bound";
//
printMethod.Invoke(obj, args);
//
//
Response.Write(result);
}
public
Type[] LoadAssembly(
string
filename)
{
Type[] functionList
=
new
Type[
10
];
Assembly assembly
=
AppDomain.CurrentDomain.Load(filename);
int
i
=
0
;
foreach
(Type t
in
assembly.GetTypes())
{
functionList[i]
=
t;
i
=
i
+
1
;
}
return
functionList;
}
protected
virtual
void
AfterLoadPage()
{
}
protected
virtual
string
InitPage()
{
return
"
BASE
"
;
}
//
Web 窗体设计器生成的代码
Web 窗体设计器生成的代码
#region
Web 窗体设计器生成的代码
override
protected
void
OnInit(EventArgs e)
{
//
//
CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base
.OnInit(e);
}
/**/
/**/
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
{
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
}
}
会员力量,点亮园子希望
刷新页面
返回顶部
Powered by:
博客园
Copyright © 2024 白桦的天空
Powered by .NET 8.0 on Kubernetes