/// <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);            
        }
        /// <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);
        }
예제 #3
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;
		}
예제 #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);
        }
예제 #5
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);
        }
예제 #6
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;
        }