📄 baseelement.cs
字号:
using System;
namespace com.use.wfp.xpdl.elements
{
using System.Reflection;
using System.Collections;
using com.use.wfp.util;
/// <summary>
/// BaseElement 的摘要说明。
/// </summary>
public class BaseElement
{
private Node node = NodeFactory.CreateEmptyNode();
protected void SetNode(Node node){
this.node = node;
}
protected BaseElement GetChild(BaseElement child, out BaseElement refChild, string xPath){
if(child == null){
refChild = (BaseElement)Type.GetType("com.use.wfp.xpdl.elements." + xPath).GetConstructor(new Type[]{}).Invoke(new object[]{});
refChild.SetNode(node.SelectSingleNode(xPath));
}else{
refChild = child;
}
return refChild;
}
protected BaseElement ChoiceChild(BaseElement child, out BaseElement refChild, string[] xPath)
{
if(child == null)
{
foreach(string name in xPath){
if( !node.SelectSingleNode(name).IsEmpty() ){
refChild = (BaseElement)Type.GetType("com.use.wfp.xpdl.elements." + name).GetConstructor(new Type[]{}).Invoke(new object[]{});
refChild.SetNode(node.SelectSingleNode(name));
return refChild;
}
}
throw new ObjectNotFound("Object Not Found In " + xPath.ToString());
}
else
{
refChild = child;
}
return refChild;
}
protected IList GetChildren(IList children, out IList refChildren, Type type, string xPath)
{
if(children == null)
{
IList nodes = node.SelectNodes(xPath);
ArrayList retList = new ArrayList();
foreach (Node xmlNode in nodes)
{
BaseElement baseElement = (BaseElement)type.GetConstructor(new Type[]{}).Invoke(new object[]{});
baseElement.SetNode(xmlNode);
retList.Add(baseElement);
}
refChildren = retList;
}
else
{
refChildren = children;
}
return refChildren;
}
protected IList GetChildren(IList children, out IList refChildren)
{
if(children == null)
{
refChildren = node.GetChildren();
}
else
{
refChildren = children;
}
return refChildren;
}
protected String GetChildText(String text, out String refText, string childName)
{
if(text == null)
{
refText = node.SelectSingleNode(childName + "/text()[1]").GetText();
}
else
{
refText = text;
}
return refText;
}
protected String GetAttribute(String attr, out String refAttr, string xPath)
{
return GetAttribute(attr, out refAttr, xPath, "");
}
protected String GetAttribute(String attr, out String refAttr, string xPath, String defaultValue)
{
if(attr == null)
{
refAttr = (String)node.GetAttributes()[xPath];
if(refAttr == null){
refAttr = defaultValue;
}
}
else
{
refAttr = attr;
}
return refAttr;
}
protected String GetText(){
return node.GetText();
}
}
public class BaseElementWithIdName:BaseElement{
private String Name;
public String GetName()
{
return GetAttribute(Name, out Name, "Name");
}
private String Id;
public String GetId()
{
return GetAttribute(Id, out Id, "Id");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -