public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result) { result = null; if (indexes[0] != null) { if (typeof(int) == indexes[0].GetType()) { int index = (int)indexes[0]; if (_xmlElement.HasElements) { int currentIndex = 0; foreach (XElement xelem in _xmlElement.Elements()) { if (currentIndex == index) { if (xelem.NodeType == XmlNodeType.Element && !xelem.HasElements) { if (xelem.HasAttributes) { result = new DynamicXMLObject(xelem); } else { result = xelem.Value; } return(true); } else if ((_xmlElement.NodeType == XmlNodeType.Element || _xmlElement.NodeType == XmlNodeType.Document) && xelem.HasElements) { result = new DynamicXMLObject(xelem); } return(true); } currentIndex++; } } } else if (typeof(string) == indexes[0].GetType()) { string attributeName = (string)indexes[0]; result = _xmlElement.Attribute(XName.Get(attributeName)).Value; return(true); } } return(false); }
public override bool TryGetMember(GetMemberBinder binder, out object result) { result = null; if (binder.Name == _value) { result = _xmlElement.Value; return(true); } if (_xmlElement.NodeType == XmlNodeType.Text) { result = _xmlElement.Value; return(true); } else if (_xmlElement.NodeType == XmlNodeType.Element || _xmlElement.NodeType == XmlNodeType.Document) { if (_xmlElement.HasElements) { foreach (XElement xelem in _xmlElement.Elements()) { if (xelem.Name.LocalName.Equals(binder.Name)) { if (xelem.NodeType == XmlNodeType.Element && !xelem.HasElements && !xelem.HasAttributes) { result = xelem.Value; return(true); } else if ((xelem.NodeType == XmlNodeType.Element || xelem.NodeType == XmlNodeType.Document) && (xelem.HasElements || xelem.HasAttributes)) { result = new DynamicXMLObject(xelem); } return(true); } } } } return(false); }