Ejemplo n.º 1
0
        //动态绑定
        public static void DynamicBind()
        {
            Console.WriteLine("\n------------动态绑定-----------------");
            dynamic person = DynamicXml.Parse(@"<Person>
            <FirstName>lee</FirstName>
            <LastName>xifoeng</LastName>
            </Person>");

            Console.WriteLine(person.FirstName);
        }
Ejemplo n.º 2
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            bool success = false;

            result = null;
            XElement firstDecendant = Element.Descendants(binder.Name).FirstOrDefault();

            if (firstDecendant != null)
            {
                if (firstDecendant.Descendants().Count() > 0)
                {
                    result = new DynamicXml(firstDecendant);
                }
                else
                {
                    result = firstDecendant.Value;
                }
                success = true;
            }
            return(success);
        }