/// <summary> /// 从TypeItem中实例化一个对象 /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public static object LoadType(TypeItem item) { //创建实例 object obj = LoadTypeInstance(item.Type); //设置参数 if (item.Params != null) { foreach (ParamItem p in item.Params) { SetParamPropValue(obj, p); } } //对象参数要递归创建对象后给属性赋值 if (item.Types != null) { foreach (TypeItem t in item.Types) { PropertyInfo pInfo = obj.GetType().GetProperty(t.Name); if (pInfo == null) { throw new ApplicationException(string.Format("Property '{0}' can not found, type {1}", t.Name, obj.GetType())); } pInfo.SetValue(obj, LoadType(t), null); } } return(obj); }
public object Create(object parent, object configContext, XmlNode section) { string xml = section.InnerXml; XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(xml); XmlNodeList nodes = xDoc.SelectNodes("//services/type"); WorkflowRuntime runtime = new WorkflowRuntime(); foreach (XmlNode node in nodes) { if (node.NodeType == XmlNodeType.Element) { StringReader sr = new StringReader(node.OuterXml); using (XmlTextReader xr = new XmlTextReader(sr)) { XmlSerializer serializer = new XmlSerializer(typeof(TypeItem)); TypeItem item = (TypeItem)serializer.Deserialize(xr); runtime.AddService(ConfigurationHelper.LoadType(item)); } } } runtime.StartRuntime(); return(runtime); }