Exemple #1
0
        public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
        {
            var parser         = new Regex("(?<element>.*)With(?<attribute>.*)");
            var match          = parser.Match(binder.Name);
            var elementName    = match.Groups["element"].Captures.Cast <Capture>().First().Value;
            var attributeName  = match.Groups["attribute"].Captures.Cast <Capture>().First().Value;
            var attributeValue = (string)args[0];

            var element = _element.Elements(elementName).Where(e =>
            {
                var attribute = e.Attributes().First(a => string.Compare(a.Name.LocalName, attributeName, StringComparison.InvariantCultureIgnoreCase) == 0);
                return(attribute.Value == attributeValue);
            }).FirstOrDefault();

            if (element == null)
            {
                result = null;
            }
            else
            {
                result = new SimpleXmlElement(element);
            }

            return(result != null);
        }
Exemple #2
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            switch (binder.Name)
            {
            case "Attributes":
                result = new SimpleXmlAttributes(_element);
                break;

            case "Value":
                result = _element.Value;
                break;

            default:
                var element = _element.Element(binder.Name);
                if (element == null)
                {
                    result = null;
                }
                else
                {
                    result = new SimpleXmlElement(element);
                }
                break;
            }

            return(result != null);
        }
Exemple #3
0
 public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
 {
     var element = _document.Root.Element(binder.Name);
     if (element == null)
         result = null;
     else
         result = new SimpleXmlElement(element);
     return result != null;
 }
Exemple #4
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            var element = _document.Root.Element(binder.Name);

            if (element == null)
            {
                result = null;
            }
            else
            {
                result = new SimpleXmlElement(element);
            }
            return(result != null);
        }
Exemple #5
0
        public override bool TryInvokeMember(System.Dynamic.InvokeMemberBinder binder, object[] args, out object result)
        {
            var parser = new Regex("(?<element>.*)With(?<attribute>.*)");
            var match = parser.Match(binder.Name);
            var elementName = match.Groups["element"].Captures.Cast<Capture>().First().Value;
            var attributeName = match.Groups["attribute"].Captures.Cast<Capture>().First().Value;
            var attributeValue = (string)args[0];

            var element = _element.Elements(elementName).Where(e =>
            {
                var attribute = e.Attributes().First(a => string.Compare(a.Name.LocalName, attributeName, StringComparison.InvariantCultureIgnoreCase) == 0);
                return attribute.Value == attributeValue;
            }).FirstOrDefault();
            if (element == null)
                result = null;
            else
                result = new SimpleXmlElement(element);

            return result != null;
        }
Exemple #6
0
        public override bool TryGetMember(System.Dynamic.GetMemberBinder binder, out object result)
        {
            switch (binder.Name)
            {
                case "Attributes":
                    result = new SimpleXmlAttributes(_element);
                    break;
                case "Value":
                    result = _element.Value;
                    break;
                default:
                    var element = _element.Element(binder.Name);
                    if (element == null)
                        result = null;
                    else
                        result = new SimpleXmlElement(element);
                    break;
            }

            return result != null;
        }