상속: Castle.Components.DictionaryAdapter.DictionaryBehaviorAttribute, IDictionaryInitializer, IDictionaryPropertyGetter, IDictionaryPropertySetter, IDictionaryCreateStrategy, IDictionaryCopyStrategy
예제 #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)));
        }
예제 #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);
        }
예제 #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));
        }
예제 #4
0
		protected XPathAdapter(XPathNavigator source, XPathAdapter parent)
		{
			Parent = parent;
			Context = parent.Context.CreateChild(null);
			root = source.Clone();
		}
예제 #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);
		}
예제 #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);
		}
예제 #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;
		}
예제 #8
0
 protected XPathAdapter(Func <XPathNavigator> createSource, XPathAdapter parent)
 {
     Parent     = parent;
     Context    = parent.Context.CreateChild(null);
     createRoot = createSource;
 }
예제 #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);
        }
예제 #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);
 }
예제 #11
0
 protected XPathAdapter(XPathNavigator source, XPathAdapter parent)
 {
     Parent  = parent;
     Context = parent.Context.CreateChild(null);
     root    = source.Clone();
 }
예제 #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));
        }
예제 #13
0
		protected XPathAdapter(Func<XPathNavigator> createSource, XPathAdapter parent)
		{
			this.parent = parent;
			context = parent.context.CreateChild();
			createRoot = createSource;
		}
예제 #14
0
		protected XPathAdapter(XPathNavigator source, XPathAdapter parent)
		{
			this.parent = parent;
			context = parent.context.CreateChild();
			root = source.Clone();
		}
예제 #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;
		}
예제 #16
0
		protected XPathAdapter(Func<XPathNavigator> createSource, XPathAdapter parent)
		{
			Parent = parent;
			Context = parent.Context.CreateChild(null);
			createRoot = createSource;
		}
예제 #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;
		}
예제 #18
0
        public static bool IsPropertyDefined(string propertyName, IDictionaryAdapter dictionaryAdapter)
        {
            var xpath = XPathAdapter.For(dictionaryAdapter);

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