Esempio n. 1
0
        public override void SetValue(IXmlNode node, IDictionaryAdapter parent, IXmlAccessor accessor, object oldValue, ref object value)
        {
            // Require a dictionary adapter
            var source = value as IDictionaryAdapter;

            if (source == null)
            {
                throw Error.NotDictionaryAdapter(nameof(value));
            }

            // Detect assignment of own value
            var sourceAdapter = XmlAdapter.For(source, false);

            if (sourceAdapter != null && node.PositionEquals(sourceAdapter.Node))
            {
                return;
            }

            // Create a fresh component
            var targetAdapter = new XmlAdapter(node.Save(), XmlAdapter.For(parent).References);

            if (sourceAdapter != null)
            {
                targetAdapter.References.UnionWith(sourceAdapter.References);
            }
            var component = (IDictionaryAdapter)parent.CreateChildAdapter(node.ClrType, targetAdapter);

            // Copy value onto fresh component
            source.CopyTo(component);
            value = component;
        }
Esempio n. 2
0
		public override void SetValue(IXmlNode node, IDictionaryAdapter parent, IXmlAccessor accessor, ref object value)
		{
			// Require a dictionary adapter
			var source = value as IDictionaryAdapter;
			if (source == null)
				throw Error.NotDictionaryAdapter("value");

			// Detect assignment of own value
			var sourceAdapter = XmlAdapter.For(source, false);
			if (sourceAdapter != null && node.PositionEquals(sourceAdapter.Node))
				return;

			// Create a fresh component
			var targetAdapter = new XmlAdapter(node.Save(), XmlAdapter.For(parent).References);
			if (sourceAdapter != null)
				targetAdapter.References.UnionWith(sourceAdapter.References);
			var component = (IDictionaryAdapter) parent.CreateChildAdapter(node.ClrType, targetAdapter);

			// Copy value onto fresh component
			source.CopyTo(component);
			value = component;
		}