コード例 #1
0
ファイル: XmlAccessor.cs プロジェクト: belav/Core
        public void GetCollectionItems(
            IXmlNode parentNode,
            IDictionaryAdapter parentObject,
            XmlReferenceManager references,
            IList values
            )
        {
            var cursor = SelectCollectionItems(parentNode, false);

            while (cursor.MoveNext())
            {
                object value;

                if (IsReference)
                {
                    IXmlNode node = cursor;
                    value = null;
                    object token;

                    if (references.OnGetStarting(ref node, ref value, out token))
                    {
                        value = serializer.GetValue(node, parentObject, this);
                        references.OnGetCompleted(node, value, token);
                    }
                }
                else
                {
                    value = serializer.GetValue(cursor, parentObject, this);
                }
                values.Add(value);
            }
        }
コード例 #2
0
        public void UnionWith(XmlReferenceManager other)
        {
            var visited = null as HashSet <Entry>;

            foreach (var otherEntry in other.entriesByValue)
            {
                Entry thisEntry;
                if (entriesByValue.TryGetValue(otherEntry.Key, out thisEntry))
                {
                    if (visited == null)
                    {
                        visited = new HashSet <Entry>(ReferenceEqualityComparer <Entry> .Instance);
                    }
                    else if (visited.Contains(thisEntry))
                    {
                        continue;
                    }
                    visited.Add(thisEntry);

                    foreach (var otherValue in otherEntry.Value.Values)
                    {
                        var otherTarget = otherValue.Value.Target;
                        if (otherTarget == null ||
                            otherTarget == otherEntry.Key ||
                            entriesByValue.ContainsKey(otherTarget))
                        {
                            continue;
                        }
                        AddValueCore(thisEntry, otherValue.Type, otherTarget, false);
                    }
                }
            }
        }
コード例 #3
0
ファイル: XmlAccessor.cs プロジェクト: belav/Core
        public object GetValue(
            IXmlNode node,
            IDictionaryAdapter parentObject,
            XmlReferenceManager references,
            bool nodeExists,
            bool orStub
            )
        {
            object value;

            if ((nodeExists || orStub) && IsReference)
            {
                value = null;
                object token;

                if (references.OnGetStarting(ref node, ref value, out token))
                {
                    value = GetValueCore(node, parentObject, nodeExists, orStub);
                    references.OnGetCompleted(node, value, token);
                }
            }
            else
            {
                value = GetValueCore(node, parentObject, nodeExists, orStub);
            }
            return(value);
        }
コード例 #4
0
ファイル: XmlAccessor.cs プロジェクト: chenmsg/sujin
        protected void RemoveCollectionItems(IXmlNode parentNode, XmlReferenceManager references, object value)
        {
            var collection = value as ICollectionProjection;

            if (collection != null)
            {
                collection.Clear();
                return;
            }

            var itemType    = clrType.GetCollectionItemType();
            var accessor    = GetCollectionAccessor(itemType);
            var cursor      = accessor.SelectCollectionItems(parentNode, true);
            var isReference = IsReference;

            var items = value as IEnumerable;

            if (items != null)
            {
                foreach (var item in items)
                {
                    if (!cursor.MoveNext())
                    {
                        break;
                    }
                    if (isReference)
                    {
                        references.OnAssigningNull(cursor, item);
                    }
                }
            }

            cursor.Reset();
            cursor.RemoveAllNext();
        }
コード例 #5
0
ファイル: XPathBehaviorAccessor.cs プロジェクト: belav/Core
 public override object GetPropertyValue(
     IXmlNode parentNode,
     IDictionaryAdapter parentObject,
     XmlReferenceManager references,
     bool orStub
     )
 {
     return(GetPropertyValueCore(parentNode, parentObject, references, orStub)
            ?? GetDefaultPropertyValue(parentNode, parentObject, references, orStub));
 }
コード例 #6
0
ファイル: XPathBehaviorAccessor.cs プロジェクト: belav/Core
 private object GetDefaultPropertyValue(
     IXmlNode parentNode,
     IDictionaryAdapter parentObject,
     XmlReferenceManager references,
     bool orStub
     )
 {
     return(defaultAccessor != null
       ? defaultAccessor.GetPropertyValue(parentNode, parentObject, references, orStub)
       : null);
 }
コード例 #7
0
ファイル: XPathBehaviorAccessor.cs プロジェクト: belav/Core
 private object GetPropertyValueCore(
     IXmlNode parentNode,
     IDictionaryAdapter parentObject,
     XmlReferenceManager references,
     bool orStub
     )
 {
     return(SelectsNodes
       ? base.GetPropertyValue(parentNode, parentObject, references, orStub)
       : Evaluate(parentNode));
 }
コード例 #8
0
ファイル: XmlAdapter.cs プロジェクト: JustF2A/Castle
        /// <summary>
        /// Initializes a new instance of the <see cref="XmlAdapter"/> class
        /// that represents a child object in a larger object graph.
        /// </summary>
        public XmlAdapter(IXmlNode node, XmlReferenceManager references)
        {
            if (node == null)
            {
                throw Error.ArgumentNull("node");
            }
            if (references == null)
            {
                throw Error.ArgumentNull("references");
            }

            this.node       = node;
            this.references = references;
        }
コード例 #9
0
ファイル: XmlAccessor.cs プロジェクト: belav/Core
        public virtual void SetPropertyValue(
            IXmlNode parentNode,
            IDictionaryAdapter parentObject,
            XmlReferenceManager references,
            object oldValue,
            ref object value
            )
        {
            var cursor = IsCollection
                ? SelectCollectionNode(parentNode, true)
                : SelectPropertyNode(parentNode, true);

            SetValue(cursor, parentObject, references, cursor.MoveNext(), oldValue, ref value);
        }
コード例 #10
0
ファイル: XPathBehaviorAccessor.cs プロジェクト: belav/Core
 public override void SetPropertyValue(
     IXmlNode parentNode,
     IDictionaryAdapter parentObject,
     XmlReferenceManager references,
     object oldValue,
     ref object value
     )
 {
     if (SelectsNodes)
     {
         base.SetPropertyValue(parentNode, parentObject, references, oldValue, ref value);
     }
     else
     {
         throw Error.XPathNotCreatable(path);
     }
 }
コード例 #11
0
ファイル: XmlAccessor.cs プロジェクト: belav/Core
        public virtual object GetPropertyValue(
            IXmlNode parentNode,
            IDictionaryAdapter parentObject,
            XmlReferenceManager references,
            bool orStub
            )
        {
            if (orStub)
            {
                orStub &= serializer.CanGetStub;
            }

            var cursor = IsCollection
                ? SelectCollectionNode(parentNode, orStub)
                : SelectPropertyNode(parentNode, orStub);

            return(GetValue(cursor, parentObject, references, cursor.MoveNext(), orStub));
        }
コード例 #12
0
 public override void SetValue(
     IXmlCursor cursor,
     IDictionaryAdapter parentObject,
     XmlReferenceManager references,
     bool hasCurrent,
     object oldValue,
     ref object newValue
     )
 {
     if (newValue == null && IsCollection)
     {
         base.RemoveCollectionItems(cursor, references, oldValue);
     }
     else
     {
         base.SetValue(cursor, parentObject, references, hasCurrent, oldValue, ref newValue);
     }
 }
コード例 #13
0
        public XmlCollectionAdapter(
            IXmlNode parentNode,
            IDictionaryAdapter parentObject,
            IXmlCollectionAccessor accessor)
        {
            items = new List <XmlCollectionItem <T> >();

            this.accessor     = accessor;
            this.cursor       = accessor.SelectCollectionItems(parentNode, true);
            this.parentNode   = parentNode;
            this.parentObject = parentObject;
            this.references   = XmlAdapter.For(parentObject).References;

            while (cursor.MoveNext())
            {
                items.Add(new XmlCollectionItem <T>(cursor.Save()));
            }
        }
コード例 #14
0
ファイル: XmlAdapter.cs プロジェクト: JustF2A/Castle
        private void InitializePrimary(DictionaryAdapterMeta meta, IDictionaryAdapter dictionaryAdapter)
        {
            RequireXmlMeta(meta);
            primaryXmlMeta = meta.GetXmlMeta();

            if (node == null)
            {
                node = GetBaseNode();
            }
            if (!node.IsReal)
            {
                node.Realized += HandleNodeRealized;
            }

            if (references == null)
            {
                references = new XmlReferenceManager(node, DefaultXmlReferenceFormat.Instance);
            }
            InitializeReference(this);
        }
コード例 #15
0
        public void UnionWith(XmlReferenceManager other)
        {
            var visited = null as HashSet <Entry>;

            foreach (var keyValue in other.entriesByValue.Keys)
            {
                Entry thisEntry;
                if (entriesByValue.TryGetValue(keyValue, out thisEntry))
                {
                    if (visited == null)
                    {
                        visited = new HashSet <Entry>(ReferenceEqualityComparer <Entry> .Instance);
                    }
                    else if (visited.Contains(thisEntry))
                    {
                        continue;
                    }
                    visited.Add(thisEntry);

                    var otherEntry = other.entriesByValue[keyValue];

                    foreach (var otherItem in otherEntry.Values)
                    {
                        if (otherItem.Value == keyValue)
                        {
                            continue;
                        }
                        if (entriesByValue.ContainsKey(otherItem.Value))
                        {
                            continue;
                        }
                        AddValueCore(thisEntry, otherItem.Type, otherItem.Value, false);
                    }
                }
            }
        }
コード例 #16
0
ファイル: XmlAccessor.cs プロジェクト: elevine/Core
		public virtual object GetPropertyValue(IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, bool orStub)
		{
			if (orStub) orStub &= serializer.CanGetStub;

			var cursor = IsCollection
				? SelectCollectionNode(parentNode, orStub)
				: SelectPropertyNode  (parentNode, orStub);

			return GetValue(cursor, parentObject, references, cursor.MoveNext(), orStub);
		}
コード例 #17
0
ファイル: XmlReferenceManager.cs プロジェクト: elevine/Core
		public void UnionWith(XmlReferenceManager other)
		{
			var visited = null as HashSet<Entry>;

			foreach (var otherEntry in other.entriesByValue)
			{
				Entry thisEntry;
				if (entriesByValue.TryGetValue(otherEntry.Key, out thisEntry))
				{
					if (visited == null)
						visited = new HashSet<Entry>(ReferenceEqualityComparer<Entry>.Instance);
					else if (visited.Contains(thisEntry))
						continue;
					visited.Add(thisEntry);

					foreach (var otherValue in otherEntry.Value.Values)
					{
						var otherTarget = otherValue.Value.Target;
						if (otherTarget == null           ||
							otherTarget == otherEntry.Key ||
							entriesByValue.ContainsKey(otherTarget))
							{ continue; }
						AddValueCore(thisEntry, otherValue.Type, otherTarget, false);
					}
				}
			}
		}
コード例 #18
0
ファイル: XmlAccessor.cs プロジェクト: chenmsg/sujin
        public virtual void SetValue(IXmlCursor cursor, IDictionaryAdapter parentObject, XmlReferenceManager references,
                                     bool hasCurrent, object oldValue, ref object newValue)
        {
            var hasValue    = null != newValue;
            var isNillable  = this.IsNillable;
            var isReference = this.IsReference;

            var clrType = hasValue
                                ? newValue.GetComponentType()
                                : this.clrType;

            if (hasValue || isNillable)
            {
                if (hasCurrent)
                {
                    Coerce(cursor, clrType, !hasValue && cursor.IsAttribute);                     // TODO: Refactor. (NB: && isNillable is emplied)
                }
                else
                {
                    cursor.Create(clrType);
                }
            }
            else if (!hasCurrent)
            {
                // No node exists + no value to assign + and not nillable = no work to do
                return;
            }

            object token = null;

            if (isReference)
            {
                if (!references.OnAssigningValue(cursor, oldValue, ref newValue, out token))
                {
                    return;
                }
            }

            var givenValue = newValue;

            if (hasValue)
            {
                serializer.SetValue(cursor, parentObject, this, oldValue, ref newValue);
            }
            else if (isNillable)
            {
                cursor.IsNil = true;
            }
            else
            {
                cursor.Remove(); cursor.RemoveAllNext();
            }

            if (isReference)
            {
                references.OnAssignedValue(cursor, givenValue, newValue, token);
            }
        }
コード例 #19
0
			public void SetUp()
			{
				OriginalXml = GetXmlText();
				Document    = Xml(OriginalXml);
				OriginalXml = Document.OuterXml;
				Namespaces  = new XmlContextBase();
				Node        = new SysXmlNode(Document.DocumentElement, typeof(object), Namespaces);
				Manager     = new XmlReferenceManager(Node, DefaultXmlReferenceFormat.Instance);
			}
コード例 #20
0
ファイル: XmlAccessor.cs プロジェクト: elevine/Core
		protected void RemoveCollectionItems(IXmlNode parentNode, XmlReferenceManager references, object value)
		{
			var collection = value as ICollectionProjection;
			if (collection != null)
			{
				collection.Clear();
				return;
			}

			var itemType    = clrType.GetCollectionItemType();
			var accessor    = GetCollectionAccessor(itemType);
			var cursor      = accessor.SelectCollectionItems(parentNode, true);
			var isReference = IsReference;

			var items = value as IEnumerable;
			if (items != null)
			{
				foreach (var item in items)
				{
					if (!cursor.MoveNext())
						break;
					if (isReference)
						references.OnAssigningNull(cursor, item);
				}
			}

			cursor.Reset();
			cursor.RemoveAllNext();
		}
コード例 #21
0
ファイル: XmlAccessor.cs プロジェクト: elevine/Core
		public void GetCollectionItems(IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references, IList values)
		{
			var cursor = SelectCollectionItems(parentNode, false);

			while (cursor.MoveNext())
			{
				object value;

				if (IsReference)
				{
					IXmlNode node = cursor;
					value = null;
					object token;

					if (references.OnGetStarting(ref node, ref value, out token))
					{
						value = serializer.GetValue(node, parentObject, this);
						references.OnGetCompleted(node, value, token);
					}
				}
				else
				{
					value = serializer.GetValue(cursor, parentObject, this);
				}
				values.Add(value);
			}
		}
コード例 #22
0
ファイル: XmlAccessor.cs プロジェクト: elevine/Core
		public virtual void SetValue(IXmlCursor cursor, IDictionaryAdapter parentObject, XmlReferenceManager references,
			bool hasCurrent, object oldValue, ref object newValue)
		{
			var hasValue    = null != newValue;
			var isNillable  = this.IsNillable;
			var isReference = this.IsReference;

			var clrType = hasValue
				? newValue.GetComponentType()
				: this.clrType;

			if (hasValue || isNillable)
			{
				if (hasCurrent)
					Coerce(cursor, clrType, !hasValue && cursor.IsAttribute); // TODO: Refactor. (NB: && isNillable is emplied)
				else
					cursor.Create(clrType);
			}
			else if (!hasCurrent)
			{
				// No node exists + no value to assign + and not nillable = no work to do
				return;
			}

			object token = null;
			if (isReference)
				if (!references.OnAssigningValue(cursor, oldValue, ref newValue, out token))
					return;

			var givenValue = newValue;

			if (hasValue)
				serializer.SetValue(cursor, parentObject, this, oldValue, ref newValue);
			else if (isNillable)
				cursor.IsNil = true;
			else
				{ cursor.Remove(); cursor.RemoveAllNext(); }

			if (isReference)
				references.OnAssignedValue(cursor, givenValue, newValue, token);
		}
コード例 #23
0
ファイル: XmlAccessor.cs プロジェクト: elevine/Core
		public virtual void SetPropertyValue(IXmlNode parentNode, IDictionaryAdapter parentObject, XmlReferenceManager references,
			object oldValue, ref object value)
		{
			var cursor = IsCollection
				? SelectCollectionNode(parentNode, true)
				: SelectPropertyNode  (parentNode, true);
				
			SetValue(cursor, parentObject, references, cursor.MoveNext(), oldValue, ref value);
		}
コード例 #24
0
ファイル: XmlAccessor.cs プロジェクト: elevine/Core
		public object GetValue(IXmlNode node, IDictionaryAdapter parentObject, XmlReferenceManager references, bool nodeExists, bool orStub)
		{
			object value;

			if ((nodeExists || orStub) && IsReference)
			{
				value = null;
				object token;

				if (references.OnGetStarting(ref node, ref value, out token))
				{
					value = GetValueCore(node, parentObject, nodeExists, orStub);
					references.OnGetCompleted(node, value, token);
				}
			}
			else
			{
				value = GetValueCore(node, parentObject, nodeExists, orStub);
			}
			return value;
		}
コード例 #25
0
ファイル: XmlReferenceManager.cs プロジェクト: RemiBou/Core
		public void UnionWith(XmlReferenceManager other)
		{
			var visited = null as HashSet<Entry>;

			foreach (var keyValue in other.entriesByValue.Keys)
			{
				Entry thisEntry;
				if (entriesByValue.TryGetValue(keyValue, out thisEntry))
				{
					if (visited == null)
						visited = new HashSet<Entry>(ReferenceEqualityComparer<Entry>.Instance);
					else if (visited.Contains(thisEntry))
						continue;
					visited.Add(thisEntry);

				    var otherEntry = other.entriesByValue[keyValue];

					foreach (var otherItem in otherEntry.Values)
					{
						if (otherItem.Value == keyValue)
							continue;
						if (entriesByValue.ContainsKey(otherItem.Value))
							continue;
						AddValueCore(thisEntry, otherItem.Type, otherItem.Value, false);
					}
				}
			}
		}