/// <summary>
        /// Converts the XmlNode data passed in, back to an actual
        /// .NET instance object.
        /// </summary>
        /// <returns>Object created from the XML.</returns>
        public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context)
        {
			object array;

			if ( xml.Attributes[ "ref" ] != null )
			{
				int stackIx		= int.Parse( xml.Attributes[ "ref" ].Value );
				array			= context.GetStackObject( stackIx ) as Array;
			}
			else
			{
			    array = Activator.CreateInstance(type);

                // Add the object to the stack
                context.Stack(array);
				foreach ( XmlNode child in xml.ChildNodes )
				{
					Type memberType			= null;
					IConverter conv	= context.GetConverter( child, ref memberType );									
                    object item = conv.FromXml( null, null, memberType, child, context );
				    MethodInfo method = array.GetType().GetMethod("Add");
				    method.Invoke(array, new object[] {item});
				}
			}
            return array;
            //return converter.FromXml(parent, field, type, xml, context);            
        }
Exemplo n.º 2
0
		/// <summary>
		/// Converts the XmlNode data passed in, back to an actual
		/// .NET instance object.
		/// </summary>
		/// <returns>Object created from the XML.</returns>
		public object FromXml( object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context )
		{
			Array array;

			if ( xml.Attributes[ "ref" ] != null )
			{
				int stackIx		= int.Parse( xml.Attributes[ "ref" ].Value );
				array			= context.GetStackObject( stackIx ) as Array;
			}
			else
			{
				int childCount	= xml.ChildNodes.Count;
				array			= Activator.CreateInstance( type, new object[] { childCount } ) as Array;

                // Add the object to the stack
                context.Stack(array);
				int i			= 0;
				foreach ( XmlNode child in xml.ChildNodes )
				{
					Type memberType			= null;
					IConverter converter	= context.GetConverter( child, ref memberType );
				
					array.SetValue( converter.FromXml( null, null, memberType, child, context ), i );

					i++;
				}
			}
			
			return array;
		}
        /// <summary>
        /// Converts the XmlNode data passed in, back to an actual
        /// .NET instance object.
        /// </summary>
        /// <returns>Object created from the XML.</returns>
        public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context)
        {
            object array;

            if (xml.Attributes["ref"] != null)
            {
                int stackIx = int.Parse(xml.Attributes["ref"].Value);
                array = context.GetStackObject(stackIx) as Array;
            }
            else
            {
                array = Activator.CreateInstance(type);

                // Add the object to the stack
                context.Stack(array);
                foreach (XmlNode child in xml.ChildNodes)
                {
                    Type       memberType = null;
                    IConverter conv       = context.GetConverter(child, ref memberType);
                    object     item       = conv.FromXml(null, null, memberType, child, context);
                    MethodInfo method     = array.GetType().GetMethod("Add");
                    method.Invoke(array, new object[] { item });
                }
            }
            return(array);
            //return converter.FromXml(parent, field, type, xml, context);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Converts the XmlNode data passed in, back to an actual
        /// .NET instance object.
        /// </summary>
        /// <returns>Object created from the XML.</returns>
        public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context)
        {
            Array array;

            if (xml.Attributes["ref"] != null)
            {
                int stackIx = int.Parse(xml.Attributes["ref"].Value);
                array = context.GetStackObject(stackIx) as Array;
            }
            else
            {
                int childCount = xml.ChildNodes.Count;
                array = Activator.CreateInstance(type, new object[] { childCount }) as Array;

                // Add the object to the stack
                context.Stack(array);
                int i = 0;
                foreach (XmlNode child in xml.ChildNodes)
                {
                    Type       memberType = null;
                    IConverter converter  = context.GetConverter(child, ref memberType);

                    array.SetValue(converter.FromXml(null, null, memberType, child, context), i);

                    i++;
                }
            }

            return(array);
        }
Exemplo n.º 5
0
		/// <summary>
		/// Converts the object passed in to its XML representation.
		/// The XML string is written on the XmlTextWriter.
		/// </summary>
		public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context)
		{
			Array array				= value as Array;
			Type arrayType			= array.GetType();

			context.WriteStartTag( arrayType, field, xml );
			
			int stackIx	= context.GetStackIndex( value );

			if ( stackIx >= 0 )
				xml.WriteAttributeString( "ref", stackIx.ToString() );
			else
			{
				context.Stack( array );

				foreach ( object child in array )
				{
					IConverter converter;

					if ( child != null )
						converter = context.GetConverter( child.GetType() );
					else
						converter = context.GetConverter( null );

                    if (converter == null) throw new ConversionException("Couldnot find converter for: " + child.GetType() + " having value: " + child);
					converter.ToXml( child, null, xml, context );
				}
			}

			context.WriteEndTag( arrayType, field, xml );
		}
Exemplo n.º 6
0
        private void WriteAfterStartTag(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context, Type type)
        {
            int stackIx = context.GetStackIndex(value);

            if (stackIx >= 0)
                xml.WriteAttributeString("ref", stackIx.ToString());
            else
            {
                context.Stack(value, type);

                if (value != null)
                    ToXmlAs(context, type, value, xml);
            }

            context.WriteEndTag(type, field, xml);
        }
Exemplo n.º 7
0
        private void WriteAfterStartTag(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context, Type type)
        {
            int stackIx = context.GetStackIndex(value);

            if (stackIx >= 0)
            {
                xml.WriteAttributeString("ref", stackIx.ToString());
            }
            else
            {
                context.Stack(value, type);

                if (value != null)
                {
                    ToXmlAs(context, type, value, xml);
                }
            }

            context.WriteEndTag(type, field, xml);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Converts the object passed in to its XML representation.
        /// The XML string is written on the XmlTextWriter.
        /// </summary>
        public void ToXml(object value, FieldInfo field, XmlTextWriter xml, IMarshalContext context)
        {
            Array array     = value as Array;
            Type  arrayType = array.GetType();

            context.WriteStartTag(arrayType, field, xml);

            int stackIx = context.GetStackIndex(value);

            if (stackIx >= 0)
            {
                xml.WriteAttributeString("ref", stackIx.ToString());
            }
            else
            {
                context.Stack(array);

                foreach (object child in array)
                {
                    IConverter converter;

                    if (child != null)
                    {
                        converter = context.GetConverter(child.GetType());
                    }
                    else
                    {
                        converter = context.GetConverter(null);
                    }

                    if (converter == null)
                    {
                        throw new ConversionException("Couldnot find converter for: " + child.GetType() + " having value: " + child);
                    }
                    converter.ToXml(child, null, xml, context);
                }
            }

            context.WriteEndTag(arrayType, field, xml);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Converts the XmlNode data passed in back to an actual
        /// .NET instance object.
        /// </summary>
        /// <returns>Object created from the XML.</returns>
        public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context)
        {
            object value;

            if (xml.Attributes["ref"] != null)
            {
                int stackIx = int.Parse(xml.Attributes["ref"].Value);
                value = context.GetStackObject(stackIx);
            }
            else
            {
                try
                {
                    // Check if there is a parameterless constructor
                    if (type.IsValueType || type.GetConstructor(__flags, null, new Type[0], null) != null)
                    {
                        value = Activator.CreateInstance(type, true);
                    }
                    else
                    {
                        value = DynamicInstanceBuilder.GetDynamicInstance(type);
                    }
                }
                catch (Exception e)
                {
                    throw new ConversionException("Error constructing type: " + type, e);
                }

                // Add the object to the stack
                context.Stack(value, type, xml);

                // Create a map of all fields
                FromXmlAs(context, type, value, xml);
            }
            return(value);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Converts the XmlNode data passed in back to an actual
        /// .NET instance object.
        /// </summary>
        /// <returns>Object created from the XML.</returns>
        public object FromXml(object parent, FieldInfo field, Type type, XmlNode xml, IMarshalContext context)
        {
            object value;

            if (xml.Attributes["ref"] != null)
            {
                int stackIx = int.Parse(xml.Attributes["ref"].Value);
                value = context.GetStackObject(stackIx);
            }
            else
            {
                try
                {
                        // Check if there is a parameterless constructor
                        if (type.IsValueType || type.GetConstructor(__flags, null, new Type[0], null) != null)
                            value = Activator.CreateInstance(type, true);
                        else
                            value = DynamicInstanceBuilder.GetDynamicInstance(type);
                }
                catch (Exception e)
                {
                    throw new ConversionException("Error constructing type: " + type, e);
                }

                // Add the object to the stack
                context.Stack(value, type, xml);

                // Create a map of all fields
                FromXmlAs(context, type, value, xml);
            }
            return value;
        }