コード例 #1
0
        static void Main(string[] args)
        {
            var xml  = @"
                <people>
                    <person name='Philip' />
                    <person name='Helen' />
                </people>
                ";
            var node = XElement.Parse(xml);
            var name = node.Element("person").Attribute("name");

            Console.WriteLine(name?.Value);

            dynamic dyn = new DynamicXMLNode(node);

            Console.WriteLine(dyn.person.name);
        }
コード例 #2
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            var element = node.Element(binder.Name);

            if (element != null)
            {
                result = new DynamicXMLNode(element);
                return(true);
            }
            else
            {
                var attribute = node.Attribute(binder.Name);
                if (attribute != null)
                {
                    result = attribute.Value;
                    return(true);
                }
                else
                {
                    result = null;
                    return(false);
                }
            }
        }