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); } }
public override IEnumerable <string> GetDynamicMemberNames() { // Since template DOM is sparse we need to create a list for each element foreach (var element in _elements.Elements().Where(e => e.HasAttributes && e.Attribute("name") != null)) //This should really be restricted to child elements that are in the current element's structured properties { yield return(element.Attribute("name").Value); } IXFAElement xfaElement = null; if (xfaElements.TryGetValue(_elements[0].Name.LocalName, out xfaElement)) { if (xfaElement.Properties != null) { foreach (var key in xfaElement.Properties.Keys) { yield return(key); } } } }