private LateBoundObjectTypeBuilder GetTypeBuilder(ObjectConfigurationType objectTypeDefinition)
 {
     if (!cachedTypeBuilders.ContainsKey(objectTypeDefinition.Name))
     {
         cachedTypeBuilders[objectTypeDefinition.Name] = new LateBoundObjectTypeBuilder(this, objectTypeDefinition);
     }
     return(cachedTypeBuilders[objectTypeDefinition.Name]);
 }
		public object Create(object parent, object configContext, System.Xml.XmlNode section)
		{
			var objectTypes = new Dictionary<string, ObjectConfigurationType>();
			XmlNodeList nodeObjects = section.SelectNodes(ObjectElement);
			foreach (XmlNode nodeObject in nodeObjects)
			{
				var objectType = new ObjectConfigurationType((XmlElement)nodeObject);
				objectTypes[objectType.Name] = objectType;
			}
			return objectTypes;
		}
        private object[] GetPropertyValues(ObjectConfigurationType objectTypeDefinition)
        {
            var propertyValues = new object[this.propertyValueTypes.Count];
            int refTypesCount  = 0;

            for (int i = 0; i < objectTypeDefinition.Properties.Count; i++)
            {
                var    propertyValueType = this.propertyValueTypes[i];
                object argValue;
                if (propertyValueType == typeof(RefType))
                {
                    var refType = this.propertyRefTypes[refTypesCount++];
                    argValue = factory.Create(refType.Name, refType.Type);
                }
                else
                {
                    var propertyTextValue = objectTypeDefinition.Properties[i].Value;
                    argValue = TypeSerializer.DeserializeFromString(propertyTextValue, propertyValueType);
                }
                propertyValues[i] = argValue;
            }
            return(propertyValues);
        }
        private object[] GetConstructorArgValues(ObjectConfigurationType objectTypeDefinition)
        {
            var constructorArgValues = new object[constructorValueTypes.Count];
            int refTypesCount        = 0;

            for (int i = 0; i < objectTypeDefinition.ConstructorArgs.Count; i++)
            {
                var    constructorValueType = constructorValueTypes[i];
                object argValue;
                if (constructorValueType == typeof(RefType))
                {
                    var refType = this.constructorRefTypes[refTypesCount++];
                    argValue = factory.Create(refType.Name, refType.Type);
                }
                else
                {
                    var constructorArgTextValue = objectTypeDefinition.ConstructorArgs[i].Value;
                    argValue = TypeSerializer.DeserializeFromString(constructorArgTextValue, constructorValueType);
                }
                constructorArgValues[i] = argValue;
            }
            return(constructorArgValues);
        }
		internal LateBoundObjectTypeBuilder(ObjectConfigurationTypeFactory factory, ObjectConfigurationType objectTypeDefinition)
		{
			this.factory = factory;
			constructorInfo = null;
			objectType = AssemblyUtils.FindType(objectTypeDefinition.Type);
			if (objectType == null)
			{
				throw new TypeLoadException(string.Format(ErrorTypeNotFound, objectTypeDefinition.Type));
			}
			constructorValueTypes = new List<Type>();
			constructorRefTypes = new List<RefType>();
			propertyValueTypes = new List<Type>();
			propertyRefTypes = new List<RefType>();
			properties = new List<PropertyInfo>();

			if (objectTypeDefinition.ConstructorArgs.Count > 0)
			{
				AppendConstructorDefinition(objectTypeDefinition.ConstructorArgs);
			}
			if (objectTypeDefinition.Properties.Count > 0)
			{
				AppendPropertyDefinition(objectTypeDefinition.Properties);
			}
		}
        internal LateBoundObjectTypeBuilder(ObjectConfigurationTypeFactory factory, ObjectConfigurationType objectTypeDefinition)
        {
            this.factory    = factory;
            constructorInfo = null;
            objectType      = AssemblyUtils.FindType(objectTypeDefinition.Type);
            if (objectType == null)
            {
                throw new TypeLoadException(string.Format(ErrorTypeNotFound, objectTypeDefinition.Type));
            }
            constructorValueTypes = new List <Type>();
            constructorRefTypes   = new List <RefType>();
            propertyValueTypes    = new List <Type>();
            propertyRefTypes      = new List <RefType>();
            properties            = new List <PropertyInfo>();

            if (objectTypeDefinition.ConstructorArgs.Count > 0)
            {
                AppendConstructorDefinition(objectTypeDefinition.ConstructorArgs);
            }
            if (objectTypeDefinition.Properties.Count > 0)
            {
                AppendPropertyDefinition(objectTypeDefinition.Properties);
            }
        }
		private object[] GetPropertyValues(ObjectConfigurationType objectTypeDefinition)
		{
			var propertyValues = new object[this.propertyValueTypes.Count];
			int refTypesCount = 0;
			for (int i = 0; i < objectTypeDefinition.Properties.Count; i++)
			{
				var propertyValueType = this.propertyValueTypes[i];
				object argValue;
				if (propertyValueType == typeof(RefType))
				{
					var refType = this.propertyRefTypes[refTypesCount++];
					argValue = factory.Create(refType.Name, refType.Type);
				}
				else
				{
					var propertyTextValue = objectTypeDefinition.Properties[i].Value;
					argValue = TypeSerializer.DeserializeFromString(propertyTextValue, propertyValueType);
				}
				propertyValues[i] = argValue;
			}
			return propertyValues;
		}
		private object[] GetConstructorArgValues(ObjectConfigurationType objectTypeDefinition)
		{
			var constructorArgValues = new object[constructorValueTypes.Count];
			int refTypesCount = 0;
			for (int i = 0; i < objectTypeDefinition.ConstructorArgs.Count; i++)
			{
				var constructorValueType = constructorValueTypes[i];
				object argValue;
				if (constructorValueType == typeof(RefType))
				{
					var refType = this.constructorRefTypes[refTypesCount++];
					argValue = factory.Create(refType.Name, refType.Type);
				}
				else
				{
					var constructorArgTextValue = objectTypeDefinition.ConstructorArgs[i].Value;
					argValue = TypeSerializer.DeserializeFromString(constructorArgTextValue, constructorValueType);
				}
				constructorArgValues[i] = argValue;
			}
			return constructorArgValues;
		}
		/// <summary>
		/// Use the values in the ObjectConfigurationType to create a new instance of this type
		/// </summary>
		/// <param name="objectTypeDefinition">The object type definition.</param>
		/// <param name="returnType">Type of the return.</param>
		/// <returns></returns>
		public object Create(ObjectConfigurationType objectTypeDefinition, Type returnType)
		{
			object[] constructorArgValues = GetConstructorArgValues(objectTypeDefinition);
			object[] propertyValues = GetPropertyValues(objectTypeDefinition);
			return Create(constructorArgValues, propertyValues);
		}
 /// <summary>
 /// Use the values in the ObjectConfigurationType to create a new instance of this type
 /// </summary>
 /// <param name="objectTypeDefinition">The object type definition.</param>
 /// <param name="returnType">Type of the return.</param>
 /// <returns></returns>
 public object Create(ObjectConfigurationType objectTypeDefinition, Type returnType)
 {
     object[] constructorArgValues = GetConstructorArgValues(objectTypeDefinition);
     object[] propertyValues       = GetPropertyValues(objectTypeDefinition);
     return(Create(constructorArgValues, propertyValues));
 }