/// <inheritdoc /> public object GetAdapter(Type type, IXPathNavigable xpathNavigable) { var xpath = new XPathAdapter(xpathNavigable); return(GetAdapter(type, new Hashtable(), new DictionaryDescriptor() .AddBehavior(XPathBehavior.Instance).AddBehavior(xpath))); }
private object ReadComponent(XPathResult result, bool ifExists, IDictionaryAdapter dictionaryAdapter) { XPathNavigator source; if (result.GetNavigator(false, true, out source) == false || (source == null && ifExists)) { return(null); } XPathAdapter xpathAdapter; var elementType = result.Type; if (source != null) { if (result.XmlMeta != null) { elementType = result.XmlMeta.Type; } else { var xmlType = Context.GetXmlType(source); elementType = dictionaryAdapter.GetXmlSubclass(xmlType, elementType) ?? elementType; } xpathAdapter = new XPathAdapter(source, this); } else { Func <XPathNavigator> createSource = () => result.GetNavigator(true); xpathAdapter = new XPathAdapter(createSource, this); } var component = Create(dictionaryAdapter, elementType, null, xpathAdapter); if (result.Property != null) { dictionaryAdapter.This.ExtendedProperties[result.Property.PropertyName] = component; } return(component); }
private object ReadComponent(XPathResult result, bool ifExists, IDictionaryAdapter dictionaryAdapter) { XPathNavigator source; if (result.Property != null) { ifExists = ifExists || dictionaryAdapter.Meta.Type.IsAssignableFrom(result.Property.PropertyType); } if (result.GetNavigator(false, true, out source) == false || (source == null && ifExists)) { return(null); } XPathAdapter xpathAdapter; var elementType = result.Type; if (source != null) { if (result.XmlMeta != null) { elementType = result.XmlMeta.Type; } else { var xmlType = GetEffectiveContext(dictionaryAdapter).GetXmlType(source); elementType = dictionaryAdapter.GetXmlSubclass(xmlType, elementType) ?? elementType; } xpathAdapter = new XPathAdapter(source, this); } else { Func <XPathNavigator> createSource = () => result.GetNavigator(true); xpathAdapter = new XPathAdapter(createSource, this); } return(Create(dictionaryAdapter, elementType, null, xpathAdapter)); }
protected XPathAdapter(XPathNavigator source, XPathAdapter parent) { Parent = parent; Context = parent.Context.CreateChild(null); root = source.Clone(); }
private object ReadComponent(XPathResult result, bool ifExists, IDictionaryAdapter dictionaryAdapter) { XPathNavigator source; if (result.Property != null) ifExists = ifExists || dictionaryAdapter.Meta.Type.IsAssignableFrom(result.Property.PropertyType); if (result.GetNavigator(false, true, out source) == false || (source == null && ifExists)) { return null; } XPathAdapter xpathAdapter; var elementType = result.Type; if (source != null) { if (result.XmlMeta != null) { elementType = result.XmlMeta.Type; } else { var xmlType = GetEffectiveContext(dictionaryAdapter).GetXmlType(source); elementType = dictionaryAdapter.GetXmlSubclass(xmlType, elementType) ?? elementType; } xpathAdapter = new XPathAdapter(source, this); } else { Func<XPathNavigator> createSource = () => result.GetNavigator(true); xpathAdapter = new XPathAdapter(createSource, this); } return Create(dictionaryAdapter, elementType, null, xpathAdapter); }
private static object Create(IDictionaryAdapter adapter, Type type, IDictionary dictionary, XPathAdapter xpathAdapter) { dictionary = dictionary ?? new Hashtable(); var descriptor = new DictionaryDescriptor(adapter.Meta.Behaviors); adapter.This.Descriptor.CopyBehaviors(descriptor); descriptor.AddBehavior(xpathAdapter); return adapter.This.Factory.GetAdapter(type, dictionary, descriptor); }
private object ReadComponent(XPathResult result, bool ifExists, IDictionaryAdapter dictionaryAdapter) { XPathAdapter xpathAdapter; var source = result.GetNavigator(false); if (source == null && ifExists) return null; var elementType = result.Type; if (source != null) { if (result.XmlMeta != null) { elementType = result.XmlMeta.Type; } else { var xmlType = Context.GetXmlType(source); elementType = dictionaryAdapter.GetXmlSubclass(xmlType, elementType) ?? elementType; } xpathAdapter = new XPathAdapter(source, this); } else { Func<XPathNavigator> createSource = () => result.GetNavigator(true); xpathAdapter = new XPathAdapter(createSource, this); } var component = Create(dictionaryAdapter, elementType, null, xpathAdapter); if (result.Property != null) dictionaryAdapter.This.ExtendedProperties[result.Property.PropertyName] = component; return component; }
protected XPathAdapter(Func <XPathNavigator> createSource, XPathAdapter parent) { Parent = parent; Context = parent.Context.CreateChild(null); createRoot = createSource; }
public static bool IsPropertyDefined(string propertyName, IDictionaryAdapter dictionaryAdapter, XPathAdapter xpath) { var key = dictionaryAdapter.GetKey(propertyName); if (key == null) { return(false); } var property = dictionaryAdapter.Meta.Properties[propertyName]; var result = xpath.EvaluateProperty(key, property, dictionaryAdapter); return(result.GetNavigator(false) != null); }
bool IDictionaryCopyStrategy.Copy(IDictionaryAdapter source, IDictionaryAdapter target, ref Func <PropertyDescriptor, bool> selector) { selector = selector ?? (property => XPathAdapter.IsPropertyDefined(property.PropertyName, source, this)); return(false); }
private static object Create(IDictionaryAdapter adapter, Type type, IDictionary dictionary, XPathAdapter xpathAdapter) { dictionary = dictionary ?? new Hashtable(); var descriptor = new DictionaryDescriptor(); adapter.This.Descriptor.CopyBehaviors(descriptor, b => b is XPathAdapter == false); descriptor.AddBehavior(xpathAdapter); return(adapter.This.Factory.GetAdapter(type, dictionary, descriptor)); }
protected XPathAdapter(Func<XPathNavigator> createSource, XPathAdapter parent) { this.parent = parent; context = parent.context.CreateChild(); createRoot = createSource; }
protected XPathAdapter(XPathNavigator source, XPathAdapter parent) { this.parent = parent; context = parent.context.CreateChild(); root = source.Clone(); }
private object ReadComponent(XPathResult result, bool ifExists, IDictionaryAdapter dictionaryAdapter) { XPathAdapter adapter; Func<XPathNavigator> createSource = null; var source = result.GetNavigator(false); if (source == null && ifExists) return null; var elementType = result.Type; if (source != null) { if (result.XmlMeta != null) { elementType = result.XmlMeta.Type; } else { var xmlType = context.GetXmlType(source); elementType = dictionaryAdapter.GetXmlSubclass(xmlType, elementType) ?? elementType; } adapter = new XPathAdapter(source, this); } else { if (createSource == null) { createSource = () => result.GetNavigator(true); } adapter = new XPathAdapter(createSource, this); } var component = dictionaryAdapter.This.Factory.GetAdapter(elementType, new Hashtable(), new DictionaryDescriptor().AddBehavior(XPathBehavior.Instance, adapter)); if (result.Property != null) { dictionaryAdapter.This.ExtendedProperties[result.Property.PropertyName] = component; } return component; }
protected XPathAdapter(Func<XPathNavigator> createSource, XPathAdapter parent) { Parent = parent; Context = parent.Context.CreateChild(null); createRoot = createSource; }
public static bool IsPropertyDefined(string propertyName, IDictionaryAdapter dictionaryAdapter, XPathAdapter xpath) { var key = dictionaryAdapter.GetKey(propertyName); if (key == null) return false; var property = dictionaryAdapter.This.Properties[propertyName]; var result = xpath.EvaluateProperty(key, property, dictionaryAdapter); return result.GetNavigator(false) != null; }
public static bool IsPropertyDefined(string propertyName, IDictionaryAdapter dictionaryAdapter) { var xpath = XPathAdapter.For(dictionaryAdapter); return((xpath != null) ? IsPropertyDefined(propertyName, dictionaryAdapter, xpath) : false); }