var assembly = Assembly.Load("FaultDll").CreateInstance(className, true);
if (m.Name != "ToString" && m.Name != "GetHashCode" && m.Name != "GetType" && m.Name != "Equals" && m.IsPublic)
System.Windows.Controls.RadioButton radio = new System.Windows.Controls.RadioButton();
}
/// <summary>
/// 得到方法参数
/// </summary>
/// <param name="funName"></param>
public void GetParameters(string funName)
{
foreach (MethodInfo m in methodlist)
{
if (m.Name == funName)
{
for (int i = 8; i < m.GetParameters().Count(); i++)
{
var p = m.GetParameters()[i];
StackPanel panel = new StackPanel();
panel.Name = p.Name;
panel.Orientation = System.Windows.Controls.Orientation.Horizontal;
panel.Margin = new Thickness(10, 5, 0, 0);
TextBlock tb = new TextBlock();
tb.Margin = new Thickness(10, 0, 0, 0);
tb.Text = p.Name + ":";
System.Windows.Controls.TextBox tbx = new System.Windows.Controls.TextBox();
tbx.Width = 40;
tbx.Margin = new Thickness(10, 0, 0, 0);
panel.Children.Add(tb);
panel.Children.Add(tbx);
this.parameters.Children.Add(panel);
}
}
}
}
/// <summary>
/// 调用dll函数
/// </summary>
/// <param name="fun"></param>
public void InvokeFunc(string fun)
{
try
{
ArrayList list = GetParamsArray();
Type[] types = Assembly.Load("FaultDll").GetTypes();//LoadFile
foreach (Type t in types)
{
MethodInfo m = t.GetMethod(fun);
if (m != null)
{
object o = Activator.CreateInstance(t);
object[] invokeArgs = new Object[] { resultmapA, resultmapB,bytedatas, startPositionA, endPositionA, startPositionB, endPositionB,list,null,null };
m.Invoke(o, invokeArgs);
resultmapA = invokeArgs[0] as Bitmap;//ref参数
resultmapB = invokeArgs[1] as Bitmap;
bytedatas = invokeArgs[2] as byte[];
}
}
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
}
}
反射用到的主要类: System.Type 类对于反射起着核心的作用。但它是一个抽象的基类,Type有与每种数据类型对应的派生类,我们使用这个派生类的对象的方法、字段、属性来查找有关该类型的所有信息。