예제 #1
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            int ndx = (int)indexes[0];

            result = new DynamicDataXml(_elements[ndx]);

            return(true);
        }
예제 #2
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;

            if (binder.Name == "value")
            {
                result = _elements[0].Value;
                return(true);
            }
            else if (binder.Name == "nodes")
            {
                result = new DynamicDataNodes(_elements.Elements().Select(e => new DynamicDataXml(e)).ToList());
                return(true);
            }
            else
            {
                var attr = _elements[0].Attribute(XName.Get(binder.Name));

                if (attr != null)
                {
                    result = attr;
                    return(true);
                }
                else
                {
                    var items = _elements.Elements(XName.Get(binder.Name));

                    if (items == null || items.Count() == 0)
                    {
                        return(false);
                    }

                    result = new DynamicDataXml(items);
                    return(true);
                }
            }
        }