Пример #1
0
        private void SetValue(IXmlCursor cursor, object oldValue, ref T value)
        {
            object obj = value;

            accessor.SetValue(cursor, parentObject, references, true, oldValue, ref obj);
            value = (T)(obj ?? default(T));
        }
Пример #2
0
        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);
            }
        }
Пример #3
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);
     }
 }
Пример #4
0
 private void Coerce(IXmlCursor cursor, Type clrType, bool replace)
 {
     if (replace)
     {
         cursor.Remove();
         cursor.MoveNext();
         cursor.Create(ClrType);
     }
     else
     {
         cursor.Coerce(clrType);
     }
 }
Пример #5
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()));
            }
        }
Пример #6
0
 public static void SetReference(this IXmlCursor cursor, string id)
 {
     cursor.SetAttribute(XRef.Ref, id);
 }
Пример #7
0
 public static void SetId(this IXmlCursor node, string id)
 {
     node.SetAttribute(XRef.Id, id);
 }
Пример #8
0
		private void Coerce(IXmlCursor cursor, Type clrType, bool replace)
		{
			if (replace)
			{
				cursor.Remove();
				cursor.MoveNext();
				cursor.Create(ClrType);
			}
			else cursor.Coerce(clrType);
		}
Пример #9
0
		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);
		}