Inheritance: Castle.Components.DictionaryAdapter.DictionaryBehaviorAttribute, IDictionaryInitializer, IDictionaryPropertyGetter, IDictionaryPropertySetter, IDictionaryCreateStrategy, IDictionaryCopyStrategy
Esempio n. 1
0
        /// <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)));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
		protected XPathAdapter(XPathNavigator source, XPathAdapter parent)
		{
			Parent = parent;
			Context = parent.Context.CreateChild(null);
			root = source.Clone();
		}
Esempio n. 5
0
		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);
		}
Esempio n. 6
0
		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);
		}
Esempio n. 7
0
		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;
		}
Esempio n. 8
0
 protected XPathAdapter(Func <XPathNavigator> createSource, XPathAdapter parent)
 {
     Parent     = parent;
     Context    = parent.Context.CreateChild(null);
     createRoot = createSource;
 }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
 bool IDictionaryCopyStrategy.Copy(IDictionaryAdapter source, IDictionaryAdapter target, ref Func <PropertyDescriptor, bool> selector)
 {
     selector = selector ?? (property => XPathAdapter.IsPropertyDefined(property.PropertyName, source, this));
     return(false);
 }
Esempio n. 11
0
 protected XPathAdapter(XPathNavigator source, XPathAdapter parent)
 {
     Parent  = parent;
     Context = parent.Context.CreateChild(null);
     root    = source.Clone();
 }
Esempio n. 12
0
        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));
        }
Esempio n. 13
0
		protected XPathAdapter(Func<XPathNavigator> createSource, XPathAdapter parent)
		{
			this.parent = parent;
			context = parent.context.CreateChild();
			createRoot = createSource;
		}
Esempio n. 14
0
		protected XPathAdapter(XPathNavigator source, XPathAdapter parent)
		{
			this.parent = parent;
			context = parent.context.CreateChild();
			root = source.Clone();
		}
Esempio n. 15
0
		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;
		}
Esempio n. 16
0
		protected XPathAdapter(Func<XPathNavigator> createSource, XPathAdapter parent)
		{
			Parent = parent;
			Context = parent.Context.CreateChild(null);
			createRoot = createSource;
		}
Esempio n. 17
0
		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;
		}
Esempio n. 18
0
        public static bool IsPropertyDefined(string propertyName, IDictionaryAdapter dictionaryAdapter)
        {
            var xpath = XPathAdapter.For(dictionaryAdapter);

            return((xpath != null) ? IsPropertyDefined(propertyName, dictionaryAdapter, xpath) : false);
        }