VB.NET Activator.CreateInstance 只需要知道类名字,就可以动态创建类对象。
来源:互联网 发布:网络爬虫有什么用 编辑:程序博客网 时间:2024/05/29 09:51
只需要知道类名字,就可以动态创建类对象。 '1、关于定义 Object类型 的访问Dim a As Object = Activator.CreateInstance(Type.GetType("项目名.类名"))'调用方法 InvokeMethoda.GetType().InvokeMember("方法名", System.Reflection.BindingFlags.InvokeMethod, Nothing, a, New Object() {"参数"}) '设置属性 SetProperty a.GetType().InvokeMember("属性名", System.Reflection.BindingFlags.SetProperty, Nothing, a, New Object() {"参数"}) '获取属性 GetProperty Dim str As Object = a.GetType().InvokeMember("属性名", System.Reflection.BindingFlags.GetProperty, Nothing, a, New Object() {}) '获取属性和设置属性的其他方法 Dim MyProperty As Reflection.PropertyInfo = a.GetType().GetProperty("属性名") MyProperty.SetValue(a, "Object值", Nothing) Dim objReturn() As Object = {} MyProperty.GetValue(a, objReturn)
'2、对已知类型的访问 Dim aa As Form = Activator.CreateInstance(Type.GetType("项目名.类名"))aa.Text = "标题" '设置属性 aa.ShowDialog() '调用方法 '3、跨程序集的访问Dim aa As Object = Reflection.Assembly.Load("程序集").CreateInstance("项目名.类名")Dim aa As Object =Activator.CreateInstance(Type.GetType("项目名.类名,程序集"))
- VB.NET Activator.CreateInstance 只需要知道类名字,就可以动态创建类对象。
- 在VC2005中,只要知道类的名字,就可以动态创建类的实例
- 释放Activator.CreateInstance创建的对象
- 用Activator .CreateInstance代替new实现类的实例化Assembly.CreateInstance()与Activator.CreateInstance()方法的区别
- 用Activator .CreateInstance代替new实现类的实例化
- 用Activator .CreateInstance代替new实现类的实例化
- 用Activator .CreateInstance代替new实现类的实例化
- Use System.Activator.CreateInstance
- Activator.CreateInstance(T) 方法
- 代替Activator.CreateInstance
- Activator.CreateInstance(T) 方法
- C# Activator.CreateInstance()方法
- Activator.CreateInstance 方法
- 用Activator .CreateInstance
- 【C#】Activator.CreateInstance用法
- java通过反射,只需要传了类名和参数,就可以根据不同参数的构造方法实例化对象
- myEclipse的注册机 (只需要用一个类就可以生成注册码)
- .Net的反射中Assembly.CreateInstance()与Activator.CreateInstance()方法的区别
- Mysql分页查询的一种实现
- DataGridView控件的数据绑定
- 关于linux相关的cpu概念
- 怎样把航显系统中航显屏幕的颜色全部变灰,为灾区默哀
- android中RadioButton的学习
- VB.NET Activator.CreateInstance 只需要知道类名字,就可以动态创建类对象。
- ffmpeg学习入门
- array_map函数在PHP类中调用内部方法简介
- 关于fscanf....WSACreateEvent和CreateEvent的点 【2013.10.17小记】
- 2013-01-04 09:26 myeclipse 8.5最新注册码(过期时间到2016年)
- java 运行带参数的书写
- Oracle 10g应用优化
- C# RaiseEvent MouseLeftButtonDownEvent
- 键盘常用ASCII码 及 键盘上每个键作用