/// <summary>
        /// Setup constructor
        /// </summary>
        /// <param name="parameters">Load parameters</param>
        /// <param name="errors">Error collection</param>
        /// <param name="reader">XML reader positioned at the element that created this builder</param>
        /// <param name="parentBuilder">Parent builder</param>
        public TypeBuilder( ComponentLoadParameters parameters, ErrorCollection errors, XmlReader reader, BaseBuilder parentBuilder )
            : base(parameters, errors, reader, parentBuilder)
        {
            //  Retrieve type name and optional assembly name from the element
            string typeName     = reader.GetAttribute( "value" );
            string assemblyName = reader.GetAttribute( "assembly" );

            if ( typeName == null )
            {
                throw new ApplicationException( string.Format( "Element \"{0}\" requires a \"type\" attribute", reader.Name ) );
            }

            Type objectType = null;
            if ( assemblyName == null )
            {
                //  Get the object type from the currently loaded set of assemblies
                objectType = AppDomainUtils.FindType( typeName );
                if ( objectType == null )
                {
                    throw new ApplicationException( string.Format( "Failed to find type \"{0}\" in app domain" , typeName ) );
                }
            }
            else
            {
                //  Get the object type from the specified assembly
                Assembly assembly = AppDomain.CurrentDomain.Load( assemblyName );
                objectType = assembly.GetType( typeName );
                if ( objectType == null )
                {
                    throw new ApplicationException( string.Format( "Failed to find type \"{0}\" in assembly \"{1}\"", typeName, assemblyName ) );
                }
            }

            BuildObject = objectType;
        }
 /// <summary>
 /// Setup constructor
 /// </summary>
 /// <param name="parameters">Load parameters</param>
 /// <param name="errors">Error collection</param>
 /// <param name="reader">XML reader positioned at the element that created this builder</param>
 /// <param name="parentBuilder">Parent builder</param>
 public ListBuilder( ComponentLoadParameters parameters, ErrorCollection errors, XmlReader reader, BaseBuilder parentBuilder )
     : base(parameters, errors, reader, parentBuilder)
 {
     //  NOTE: AP: This Just Works, because the base builder implementation checks if BuildObject is an
     //  IList, and adds child build objects to it if so... this is all we need to do (in fact, <list>
     //  is just a shorthand for <object type="System.Collections.ArrayList">)
     BuildObject = m_BuildObjects;
 }
        /// <summary>
        /// Setup constructor
        /// </summary>
        /// <param name="parameters">Load parameters</param>
        /// <param name="errors">Error collection</param>
        /// <param name="reader">XML reader positioned at the element that created this object</param>
        /// <param name="parentBuilder">Parent builder</param>
        public ObjectBuilder( ComponentLoadParameters parameters, ErrorCollection errors, XmlReader reader, BaseBuilder parentBuilder )
            : base(parameters, errors, reader, parentBuilder)
        {
            //  Retrieve type name and optional assembly name from the element
            string typeName = reader.GetAttribute( "type" );
            string assemblyName = reader.GetAttribute( "assembly" );

            Construct( reader.Name, typeName, assemblyName );
        }
        /// <summary>
        /// Setup constructor
        /// </summary>
        /// <param name="parameters">Load parameters</param>
        /// <param name="errors">Error collection</param>
        /// <param name="reader">XML reader positioned at the element that created this builder</param>
        /// <param name="parentBuilder">Parent builder</param>
        public BaseBuilder( ComponentLoadParameters parameters, ErrorCollection errors, XmlReader reader, BaseBuilder parentBuilder )
        {
            IXmlLineInfo lineInfo = reader as IXmlLineInfo;
            if ( lineInfo != null )
            {
                m_Line      = lineInfo.LineNumber;
                m_Column    = lineInfo.LinePosition;
            }

            m_ParentBuilder = parentBuilder;
            m_Errors        = errors;
            m_Parameters    = parameters;
            m_Property      = reader.GetAttribute( "property" );
            m_DynProperty   = reader.GetAttribute( "dynProperty" );
            m_Name          = reader.GetAttribute( "name" );
            m_Id            = reader.GetAttribute( "id" );
        }
        /// <summary>
        /// Setup constructor
        /// </summary>
        /// <param name="parameters">Load parameters</param>
        /// <param name="errors">Error collection</param>
        /// <param name="reader">XML reader positioned at the element that created this builder</param>
        /// <param name="parentBuilder">Parent builder</param>
        public AssetBuilder( ComponentLoadParameters parameters, ErrorCollection errors, XmlReader reader, BaseBuilder parentBuilder )
            : base(parameters, errors, reader, parentBuilder)
        {
            string assetPath = reader.GetAttribute( "path" );

            string instance = reader.GetAttribute( "instance" );
            m_Instance = string.IsNullOrEmpty( instance ) ? false : bool.Parse( instance );
            m_Loader = AssetManager.Instance.CreateLoadState( Locations.NewLocation( assetPath ), null );

            string useCurrentParams = reader.GetAttribute( "useCurrentParameters" );
            if ( useCurrentParams != null )
            {
                if ( bool.Parse( useCurrentParams ) )
                {
                    m_Loader.Parameters = Parameters;
                }
            }
        }
 /// <summary>
 /// Setup constructor
 /// </summary>
 /// <param name="parameters">Load parameters</param>
 /// <param name="errors">Error collection</param>
 /// <param name="reader">XML reader positioned at the element that created this builder</param>
 /// <param name="parentBuilder">Parent builder</param>
 public InstanceBuilder( ComponentLoadParameters parameters, ErrorCollection errors, XmlReader reader, BaseBuilder parentBuilder )
     : base(parameters, errors, reader, parentBuilder)
 {
 }
 /// <summary>
 /// Setup constructor
 /// </summary>
 /// <param name="parameters">Load parameters</param>
 /// <param name="errors">Error collection</param>
 /// <param name="reader">XML reader positioned at the element that created this object</param>
 /// <param name="parentBuilder">Parent builder</param>
 /// <param name="typeName">Name of the type to create</param>
 public ObjectBuilder( ComponentLoadParameters parameters, ErrorCollection errors, XmlReader reader, BaseBuilder parentBuilder, string typeName )
     : base(parameters, errors, reader, parentBuilder)
 {
     string assemblyName = reader.GetAttribute( "assembly" );
     Construct( reader.Name, typeName, assemblyName );
 }
 /// <summary>
 /// Setup constructor
 /// </summary>
 /// <param name="parameters">Load parameters</param>
 /// <param name="errors">Error collection</param>
 /// <param name="reader">XML reader positioned at the element that created this builder</param>
 /// <param name="parentBuilder">Parent builder</param>
 public MethodBuilder( ComponentLoadParameters parameters, ErrorCollection errors, XmlReader reader, BaseBuilder parentBuilder )
     : base(parameters, errors, reader, parentBuilder)
 {
     m_MethodName = reader.GetAttribute( "call" );
 }
 /// <summary>
 /// Calls BaseBuilder.Resolve() on the specified builder object
 /// </summary>
 public static void SafeResolve( BaseBuilder builder, bool linkBuilder )
 {
     try
     {
         builder.Resolve( linkBuilder );
     }
     catch ( Exception ex )
     {
         builder.Errors.Add( builder, ex, "Builder threw an exception during resolution phase" );
     }
 }
 /// <summary>
 /// Calls BaseBuilder.PostCreate() on the specified builder object
 /// </summary>
 public static void SafePostCreate( BaseBuilder builder )
 {
     try
     {
         builder.PostCreate( );
     }
     catch ( Exception ex )
     {
         builder.Errors.Add( builder, ex, "Builder threw an exception during post-creation phase" );
     }
 }
        /// <summary>
        /// Creates a BaseBuilder-derived object from a name
        /// </summary>
        /// <param name="parentBuilder">Parent builder</param>
        /// <param name="parameters">Load parameters</param>
        /// <param name="errors">Error collection</param>
        /// <param name="reader">XML reader</param>
        /// <returns>Returns the new builder, or null if there as an error</returns>
        public static BaseBuilder CreateBuilderFromReader( BaseBuilder parentBuilder, ComponentLoadParameters parameters, ErrorCollection errors, XmlReader reader )
        {
            BaseBuilder result = null;
            try
            {
                switch ( reader.Name )
                {
                    case "null"		: result = new ValueBuilder( parameters, errors, reader, parentBuilder, null );		break;
                    case "rb"       : result = new RootBuilder( parameters, errors, reader );							break;
                    case "object"   : result = new ObjectBuilder( parameters, errors, reader, parentBuilder );			break;
                    case "ref"      : result = new ReferenceBuilder( parameters, errors, reader, parentBuilder );		break;
                    case "asset"	: result = new AssetBuilder( parameters, errors, reader, parentBuilder );			break;
                    case "instance" : result = new InstanceBuilder( parameters, errors, reader, parentBuilder );		break;
                    case "method"	: result = new MethodBuilder( parameters, errors, reader, parentBuilder );			break;
                    case "list"     : result = new ListBuilder( parameters, errors, reader, parentBuilder );			break;
                    case "table"	: result = new DictionaryBuilder( parameters, errors, reader, parentBuilder );		break;
                    case "type"     : result = new TypeBuilder( parameters, errors, reader, parentBuilder );			break;
                    case "template"	: result = new TemplateBuilder( parameters, errors, reader, parentBuilder );		break;
                    case "location" :
                        string loc = reader.GetAttribute( "value" );
                        result = new ValueBuilder( parameters, errors,reader, parentBuilder, Locations.NewLocation( loc ) );
                        break;
                    case "dictionaryEntry"	:
                        result = new DictionaryEntryBuilder( parameters, errors, reader, parentBuilder );
                        break;
                    case "dynProperty"	:
                        object dynPropertyValue = parameters.Properties[ reader.GetAttribute( "value" ) ];
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, dynPropertyValue );
                        break;
                    case "colour"		:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, MakeColour( reader ) );
                        break;
                    case "string"		:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, reader.GetAttribute( "value" ) );
                        break;
                    case "guid"			:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, new Guid( reader.GetAttribute( "value" ) ) );
                        break;
                    case "bool"			:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, bool.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "char"			:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, char.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "byte"			:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, byte.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "sbyte"		:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, sbyte.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "short"		:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, short.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "ushort"		:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, ushort.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "int"			:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, int.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "uint"			:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, uint.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "long"			:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, long.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "ulong"		:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, ulong.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "float"		:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, float.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "double"		:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, double.Parse( reader.GetAttribute( "value" ) ) );
                        break;
                    case "timeSpan"		:
                        result = new ValueBuilder( parameters, errors, reader, parentBuilder, MakeTimeSpan( reader ) );
                        break;
                    case "point3"		:
                        {
                            float x = float.Parse( reader.GetAttribute( "x" ) );
                            float y = float.Parse( reader.GetAttribute( "y" ) );
                            float z = float.Parse( reader.GetAttribute( "z" ) );
                            result = new ValueBuilder( parameters, errors, reader, parentBuilder, new Point3( x, y, z ) );
                            break;
                        }
                    case "bigPoint3"	:
                        {
                            long x = long.Parse( reader.GetAttribute( "x" ) );
                            long y = long.Parse( reader.GetAttribute( "y" ) );
                            long z = long.Parse( reader.GetAttribute( "z" ) );
                            result = new ValueBuilder( parameters, errors, reader, parentBuilder, new BigPoint3( x, y, z ) );
                            break;
                        }
                    case "vector2"		:
                        {
                            float x = float.Parse( reader.GetAttribute( "x" ) );
                            float y = float.Parse( reader.GetAttribute( "y" ) );
                            result = new ValueBuilder( parameters, errors, reader, parentBuilder, new Vector2( x, y ) );
                            break;
                        }
                    case "vector3"		:
                        {
                            float x = float.Parse( reader.GetAttribute( "x" ) );
                            float y = float.Parse( reader.GetAttribute( "y" ) );
                            float z = float.Parse( reader.GetAttribute( "z" ) );
                            result = new ValueBuilder( parameters, errors, reader, parentBuilder, new Vector3( x, y, z ) );
                            break;
                        }
                    case "point2"   	:
                    case "quat"     	:
                        {
                            errors.Add( reader, "Element is not yet supported", reader.Name );
                            reader.Skip( );
                            break;
                        }
                    default	:
                        {
                            //	Interpret name as object type
                            string typeName = reader.Name;
                            result = new ObjectBuilder( parameters, errors, reader, parentBuilder, typeName );
                            break;
                        }
                }
            }
            catch ( Exception ex )
            {
                errors.Add( reader, ex, "Builder created from element \"{0}\" threw an exception", reader.Name );
                reader.Skip( );
            }

            if ( result != null )
            {
                string name = reader.Name;
                try
                {
                    result.ReadChildBuilders( reader );
                }
                catch ( Exception ex )
                {
                    errors.Add( reader, ex, "Exception thrown while reading children from builder \"{0}\"", name );
                }
            }

            return result;
        }
 /// <summary>
 /// Setup constructor
 /// </summary>
 /// <param name="parameters">Load parameters</param>
 /// <param name="errors">Error collection</param>
 /// <param name="reader">XML reader positioned at the element that created this builder</param>
 /// <param name="parentBuilder">Parent builder object</param>
 public ReferenceBuilder( ComponentLoadParameters parameters, ErrorCollection errors, XmlReader reader, BaseBuilder parentBuilder )
     : base(parameters, errors, reader, parentBuilder)
 {
     m_ObjectId = reader.GetAttribute( "objectId" );
     m_Properties = reader.GetAttribute( "access" );
 }