Esempio n. 1
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            int ndx = (int)indexes[0];

            result = new DynamicTemplateXml(_elements[ndx]);

            return(true);
        }
Esempio n. 2
0
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            result = null;

            // Since template DOM is sparse we need to create a list for each element
            // If we have it in the XML, return the value of the attribute
            // If we don't have it in the XML, create it, add it to Attributes collection

            // var attr = _elements[0].Attribute(XName.Get(binder.Name));

            IXFAElement xfaElement = xfaElements[_elements[0].Name.LocalName];

            IXFAProperty property;

            if (_elements[0].HasAttributes && _elements[0].Attribute(binder.Name) != null)
            {
                result = _elements[0].Attribute(binder.Name).Value;
            }
            else if (xfaElement.Properties != null && xfaElement.Properties.TryGetValue(_elements[0].Name.LocalName, out property))
            {
                if (property.Type == EnumXFAPropertyType.Property)
                {
                    var a = new XAttribute(property.Name, property.Values.First(v => v.IsDefault == true).Value);

                    _elements[0].Add(a);

                    result = a.Value;
                }
            }

            if (result != null)
            {
                return(true);
            }
            else
            {
                var items = _elements[0].Elements().Where(e => e.HasAttributes && e.Attribute("name").Value.Equals(binder.Name));

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

                result = new DynamicTemplateXml(items);

                return(true);
            }
        }