目前工程需要用到发射,谁给讲讲,有形成的文档和DEMO最好
解决方案 »
- 带图片的文章如何写入数据库??
- AxMicrosoft.Office.Interop.Owc11.AxSpreadsheet 会用的进来看下
- C#中WinForm界面的设计可以用什么模式能实现界面的灵活性
- 关于将数据分别插入数据库的问题!
- 把已知的XML文档读进treeview中
- 如何反射ascx Web用户控件
- 求《程序员教程》,《软件设计师教程》,《系统分析师教程》三本书的免费下载地址!!!!!
- DataGridView 单元格中添加按钮
- (高分求)c#调用dll的问题?
- Windows服务的定时器问题
- 请教一个ADOMD.net的初级问题
- 如何用c#设置 Excel中的cells的格式设定为“文件列”??
很详细的
我就看那个学习的反射
if (navigator.MoveToFirstAttribute())
{
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(this);
do
{
PropertyDescriptor pd = pdc[navigator.Name];
if (pd != null && pd.IsLocalizable)
{
if (!pd.IsReadOnly)
pd.SetValue(this, CreateInstanceByType(pd.PropertyType, navigator.Value));
else // Write ReadOnly Properties to XML
{
PropertyInfo pi = this.GetType().GetProperty(pd.Name);
if (pi != null && pi.CanWrite)
pi.SetValue(this, CreateInstanceByType(pd.PropertyType, navigator.Value), null);
}
}
else
Properties.Add(navigator.Name.ToUpper(), navigator.Value);
} while (navigator.MoveToNextAttribute());
}
using System.Reflection;
using System.IO;namespace BindingFlagsSnippet
{
class EntryPoint
{
static void Main(string[] args)
{
Invoke.Go();
}
}
class Invoke
{
public static void Go()
{
// BindingFlags.InvokeMethod
// Call a static method.
Type t = typeof (TestClass); Console.WriteLine();
Console.WriteLine("Invoking a static method.");
Console.WriteLine("-------------------------");
t.InvokeMember ("SayHello", BindingFlags.InvokeMethod, null, null, new object [] {}); // BindingFlags.InvokeMethod
// Call an instance method.
TestClass c = new TestClass ();
Console.WriteLine();
Console.WriteLine("Invoking an instance method.");
Console.WriteLine("----------------------------");
c.GetType().InvokeMember ("AddUp", BindingFlags.InvokeMethod, null, c, new object [] {});
c.GetType().InvokeMember ("AddUp", BindingFlags.InvokeMethod, null, c, new object [] {});
// BindingFlags.InvokeMethod
// Call a method with parameters.
object [] args = new object [] {100.09, 184.45};
object result;
Console.WriteLine();
Console.WriteLine("Invoking a method with parameters.");
Console.WriteLine("---------------------------------");
result = t.InvokeMember ("ComputeSum", BindingFlags.InvokeMethod, null, null, args);
Console.WriteLine ("{0} + {1} = {2}", args[0], args[1], result); // BindingFlags.GetField, SetField
Console.WriteLine();
Console.WriteLine("Invoking a field (getting and setting.)");
Console.WriteLine("--------------------------------------");
// Get a field value.
result = t.InvokeMember ("Name", BindingFlags.GetField, null, c, new object [] {});
Console.WriteLine ("Name == {0}", result);
// Set a field.
t.InvokeMember ("Name", BindingFlags.SetField, null, c, new object [] {"NewName"});
result = t.InvokeMember ("Name", BindingFlags.GetField, null, c, new object [] {});
Console.WriteLine ("Name == {0}", result);
Console.WriteLine();
Console.WriteLine("Invoking an indexed property (getting and setting.)");
Console.WriteLine("--------------------------------------------------");
// BindingFlags.GetProperty
// Get an indexed property value.
int index = 3;
result = t.InvokeMember ("Item", BindingFlags.GetProperty, null, c, new object [] {index});
Console.WriteLine ("Item[{0}] == {1}", index, result);
// BindingFlags.SetProperty
// Set an indexed property value.
index = 3;
t.InvokeMember ("Item", BindingFlags.SetProperty, null, c, new object [] {index, "NewValue"});
result = t.InvokeMember ("Item", BindingFlags.GetProperty , null, c, new object [] {index});
Console.WriteLine ("Item[{0}] == {1}", index, result);
....太长,只贴了部分..
object o = a.CreateInstance("abc.Class1")