/// <summary> /// 尝试获取成员值 /// </summary> /// <param name="binder">获取成员值</param> /// <param name="result">结果</param> /// <returns></returns> public override bool TryGetMember(GetMemberBinder binder, out object result) { var nextNode = new XmlNodeBuilder(binder.Name, this.parent); this.AddNode(nextNode); result = nextNode; return(true); }
/// <summary> /// 构造函数,初始化标签名、Xml父节点生成器、内容、属性字典 /// </summary> /// <param name="tagName">标签名</param> /// <param name="parent">Xml父节点生成器</param> /// <param name="innerText">内容</param> /// <param name="attributes">属性字典</param> internal XmlNodeBuilder(string tagName, XmlNodeBuilder parent, string innerText = null, IDictionary <string, string> attributes = null) { this._children = new ChildXmlNodesBuilder(); this.parent = parent; this.name = tagName; this.innerText = innerText; this.attributesDic = attributes; }
/// <summary> /// 尝试调用操作 /// </summary> /// <param name="binder">调用操作</param> /// <param name="args">参数</param> /// <param name="result">结果</param> /// <returns></returns> public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { var text = (string)args[0]; Dictionary <string, string> attr = null; if (args.Length > 1) { attr = (Dictionary <string, string>)args[1]; } var nextNode = new XmlNodeBuilder(binder.Name, this.parent, text, attr); this.parent.AddNode(nextNode); result = nextNode; return(true); }
/// <summary> /// 尝试调用成员 /// </summary> /// <param name="binder">调用操作</param> /// <param name="args">参数</param> /// <param name="result">结果</param> /// <returns></returns> public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result) { var innerText = (string)args[0]; Dictionary <string, string> attr = null; if (args.Length > 1) { attr = args[1].GetType() .GetProperties() .ToDictionary(pr => pr.Name, pr => pr.GetValue(args[1]).ToString()); } var nextNode = new XmlNodeBuilder(binder.Name, this.parent, innerText, attr); this.AddNode(nextNode); result = nextNode; return(true); }
/// <summary> /// 添加节点生成器 /// </summary> /// <param name="node">节点生成器</param> internal void AddNode(XmlNodeBuilder node) { this.children.Add(node); }
/// <summary> /// 构造函数,初始化Xml节点动态生成器 /// </summary> /// <param name="parent">Xml节点动态生成器</param> internal ChildXmlNodesBuilder(XmlNodeBuilder parent = null) { this.parent = parent; this.children = new List <XmlNodeBuilder>(); }