<?xml version="1.0" encoding="utf-8" ?> <forms-config> <action-mappings> <action name="writeMessage" type="JJSoft.TestDLL.TestClass" dllName="JJSoft.TestDLL.dll"> <forward name="success" path="" /> <forward name="faild" path="" /> </action> </action-mappings> </forms-config> 配置文件 using System.Text; using System.Xml; using System.Reflection; using System.Collections; using System.Windows.Forms; using JJSoft.FrameWork.Controls; namespace JJSoft.FrameWork.FormBase { public class FormBase : System.Windows.Forms.Form { #region const protected const string FORMS_CONFIG_FILENAME = @"forms-config.xml"; protected const string ATTRIBUTE_DLLNAME = "dllName"; protected const string ATTRIBUTE_TYPE = "type"; protected const string ATTRIBUTE_NAME = "name"; #endregion public Hashtable doPropertyCollect(List<Panel> pnlList) { Hashtable htProperty = new Hashtable(); if (pnlList !=null) { foreach (Panel pnl in pnlList) { htProperty = doPropertyCollect(pnl); } } return htProperty; } public Hashtable doPropertyCollect(Panel pnl) { Hashtable htProperty = new Hashtable(); foreach (Control ctr in pnl.Controls) { Type type = ctr.GetType(); PropertyInfo pptInfo = type.GetProperty("Property"); if (pptInfo != null) { htProperty.Add(pptInfo.GetValue(ctr,null), ctr.Text); } } return htProperty; } public void doAction(string strActionName,Hashtable propertys) { try { XmlElement actionElement; string strDllName; string strType; string strStartPath = System.Windows.Forms.Application.StartupPath + @"/"; actionElement = findElement(strActionName); strDllName = strStartPath + actionElement.GetAttribute(ATTRIBUTE_DLLNAME); strType = actionElement.GetAttribute(ATTRIBUTE_TYPE); Assembly asm = Assembly.LoadFile(strDllName); Type type = asm.GetType(strType); Object obj = asm.CreateInstance(strType); foreach (object objKey in propertys.Keys) { object propertyValue; propertyValue = propertys[objKey]; PropertyInfo pptInfo = type.GetProperty(objKey.ToString()); if (pptInfo != null) { pptInfo.SetValue(obj, propertyValue, null); } } MethodInfo mthInfo = type.GetMethod(strActionName); mthInfo.Invoke(obj, null); } catch (Exception ex) { throw ex; } } public XmlElement findElement(string strNodeName) { XmlElement actionElement; actionElement = null; XmlDocument xmlFormsConfig; xmlFormsConfig = new XmlDocument(); xmlFormsConfig.Load(FORMS_CONFIG_FILENAME); XmlElement root = xmlFormsConfig.DocumentElement; foreach (XmlElement xmlActionElement in root.FirstChild.ChildNodes) { if (strNodeName.Equals(xmlActionElement.GetAttribute(ATTRIBUTE_NAME))) { actionElement = xmlActionElement; } } return actionElement; } } } 基础类代码