コード例 #1
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            try
            {
                if (binder.Name == "Attributes")
                {
                    result = new DynamicXMLAttributesCollection(Element.Attributes);
                    return(true);
                }

                var memberElement = Element[binder.Name];
                if (memberElement.HasChildNodes)
                {
                    result = new DynamicXMLElement(memberElement);
                    return(true);
                }
                else
                {
                    result = memberElement.InnerText;
                    return(true);
                }
            }
            catch { }

            result = null;
            return(false);
        }
コード例 #2
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (binder.Name == "Attributes")
            {
                result = new DynamicXMLAttributesCollection(Element.Attributes);
                return true;
            }

            var memberElement = Element[binder.Name];

            // Child element is not present
            if (memberElement == null)
            {
                result = null;
                return false;
            }

            if (memberElement.HasChildNodes)
                result = new DynamicXMLElement(memberElement);
            else
                result = memberElement.InnerText;

            return true;
        }