Пример #1
0
        /// <summary>
        /// Resolves this managed collection at runtime.
        /// </summary>
        /// <param name="objectName">
        /// The name of the top level object that is having the value of one of it's
        /// collection properties resolved.
        /// </param>
        /// <param name="definition">
        /// The definition of the named top level object.
        /// </param>
        /// <param name="propertyName">
        /// The name of the property the value of which is being resolved.
        /// </param>
        /// <param name="resolver">
        /// The callback that will actually do the donkey work of resolving
        /// this managed collection.
        /// </param>
        /// <returns>A fully resolved collection.</returns>
        public ICollection Resolve(string objectName, IObjectDefinition definition, string propertyName, ManagedCollectionElementResolver resolver)
        {
            IList list;

            Type elementType = null;
            if (StringUtils.HasText(this.elementTypeName))
            {
                elementType = TypeResolutionUtils.ResolveType(this.elementTypeName);
            }
#if NET_2_0
            if (elementType == null)
            {
                list = new ArrayList();
            }
            else
            {
                // CLOVER:ON
                Type type = typeof(List<>);
                Type[] genericArgs = new Type[1] { elementType };
                type = type.MakeGenericType(genericArgs);

                list = (IList)ObjectUtils.InstantiateType(type);
                // CLOVER:OFF
            }
#else
            list = new ArrayList();
#endif
            for (int i = 0; i < Count; ++i)
            {
                object element = this[i];
                object resolvedElement =
                        resolver(objectName, definition, String.Format(CultureInfo.InvariantCulture, "{0}[{1}]", propertyName, i), element);

                if (elementType != null)
                {
                    try
                    {
                        resolvedElement = TypeConversionUtils.ConvertValueIfNecessary(elementType, resolvedElement, propertyName + "[" + i + "]");
                    }
                    catch (TypeMismatchException)
                    {
                        throw new TypeMismatchException(
                            String.Format(
                                    "Unable to convert managed list element '{0}' from [{1}] into [{2}] during initialization"
                                    + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?",
                                    resolvedElement, resolvedElement.GetType(), elementType, propertyName, objectName));
                    }
                }

                list.Add(resolvedElement);
            }

            return list;
        }
Пример #2
0
        /// <summary>
        /// Resolves this managed collection at runtime.
        /// </summary>
        /// <param name="objectName">
        /// The name of the top level object that is having the value of one of it's
        /// collection properties resolved.
        /// </param>
        /// <param name="definition">
        /// The definition of the named top level object.
        /// </param>
        /// <param name="propertyName">
        /// The name of the property the value of which is being resolved.
        /// </param>
        /// <param name="resolver">
        /// The callback that will actually do the donkey work of resolving
        /// this managed collection.
        /// </param>
        /// <returns>A fully resolved collection.</returns>
        public ICollection Resolve(string objectName, IObjectDefinition definition, string propertyName, ManagedCollectionElementResolver resolver)
        {
            IList list;

            Type elementType = null;

            if (StringUtils.HasText(this.elementTypeName))
            {
                elementType = TypeResolutionUtils.ResolveType(this.elementTypeName);
            }

            if (elementType == null)
            {
                list = new ArrayList();
            }
            else
            {
                // CLOVER:ON
                Type   type        = typeof(List <>);
                Type[] genericArgs = new Type[1] {
                    elementType
                };
                type = type.MakeGenericType(genericArgs);

                list = (IList)ObjectUtils.InstantiateType(type);
                // CLOVER:OFF
            }

            for (int i = 0; i < Count; ++i)
            {
                object element         = this[i];
                object resolvedElement =
                    resolver(objectName, definition, String.Format(CultureInfo.InvariantCulture, "{0}[{1}]", propertyName, i), element);

                if (elementType != null)
                {
                    try
                    {
                        resolvedElement = TypeConversionUtils.ConvertValueIfNecessary(elementType, resolvedElement, propertyName + "[" + i + "]");
                    }
                    catch (TypeMismatchException)
                    {
                        throw new TypeMismatchException(
                                  String.Format(
                                      "Unable to convert managed list element '{0}' from [{1}] into [{2}] during initialization"
                                      + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?",
                                      resolvedElement, resolvedElement.GetType(), elementType, propertyName, objectName));
                    }
                }

                list.Add(resolvedElement);
            }

            return(list);
        }
Пример #3
0
        /// <summary>
        /// Resolves this managed collection at runtime.
        /// </summary>
        /// <param name="objectName">
        /// The name of the top level object that is having the value of one of it's
        /// collection properties resolved.
        /// </param>
        /// <param name="definition">
        /// The definition of the named top level object.
        /// </param>
        /// <param name="propertyName">
        /// The name of the property the value of which is being resolved.
        /// </param>
        /// <param name="resolver">
        /// The callback that will actually do the donkey work of resolving
        /// this managed collection.
        /// </param>
        /// <returns>A fully resolved collection.</returns>
        public ICollection Resolve(
            string objectName, IObjectDefinition definition,
            string propertyName, ManagedCollectionElementResolver resolver)
        {
            IDictionary dictionary;

            Type keyType = null;

            if (StringUtils.HasText(this.keyTypeName))
            {
                keyType = TypeResolutionUtils.ResolveType(this.keyTypeName);
            }

            Type valueType = null;

            if (StringUtils.HasText(this.valueTypeName))
            {
                valueType = TypeResolutionUtils.ResolveType(this.valueTypeName);
            }

            if ((keyType == null) && (valueType == null))
            {
                dictionary = new HybridDictionary();
            }
            else
            {
                Type   type        = typeof(Dictionary <,>);
                Type[] genericArgs = new Type[2] {
                    (keyType == null) ? typeof(object) : keyType,
                    (valueType == null) ? typeof(object) : valueType
                };
                type = type.MakeGenericType(genericArgs);

                dictionary = (IDictionary)ObjectUtils.InstantiateType(type);
            }

            foreach (object key in this.Keys)
            {
                string elementName   = string.Format(CultureInfo.InvariantCulture, "{0}[{1}]", propertyName, key);
                object resolvedKey   = resolver(objectName, definition, elementName, key);
                object resolvedValue = resolver(objectName, definition, elementName, this[key]);

                if (keyType != null)
                {
                    try
                    {
                        resolvedKey = TypeConversionUtils.ConvertValueIfNecessary(keyType, resolvedKey, propertyName);
                    }
                    catch (TypeMismatchException)
                    {
                        throw new TypeMismatchException(
                                  String.Format(
                                      "Unable to convert managed dictionary key '{0}' from [{1}] into [{2}] during initialization"
                                      + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?",
                                      resolvedKey, resolvedKey.GetType(), keyType, propertyName, objectName));
                    }
                }

                if (valueType != null)
                {
                    try
                    {
                        resolvedValue = TypeConversionUtils.ConvertValueIfNecessary(valueType, resolvedValue, propertyName + "[" + resolvedKey + "]");
                    }
                    catch (TypeMismatchException)
                    {
                        throw new TypeMismatchException(
                                  String.Format(
                                      "Unable to convert managed dictionary value '{0}' from [{1}] into [{2}] during initialization"
                                      + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?",
                                      resolvedValue, resolvedValue.GetType(), valueType, propertyName, objectName));
                    }
                }

                dictionary.Add(resolvedKey, resolvedValue);
            }

            return(dictionary);
        }
Пример #4
0
		/// <summary>
		/// Resolves this managed collection at runtime.
		/// </summary>
		/// <param name="objectName">
		/// The name of the top level object that is having the value of one of it's
		/// collection properties resolved.
		/// </param>
		/// <param name="definition">
		/// The definition of the named top level object.
		/// </param>
		/// <param name="propertyName">
		/// The name of the property the value of which is being resolved.
		/// </param>
		/// <param name="resolver">
		/// The callback that will actually do the donkey work of resolving
		/// this managed collection.
		/// </param>
		/// <returns>A fully resolved collection.</returns>
		public ICollection Resolve(
			string objectName, IObjectDefinition definition,
			string propertyName, ManagedCollectionElementResolver resolver)
		{
            IDictionary dictionary;

            Type keyType = null;
            if (StringUtils.HasText(this.keyTypeName))
            {
                keyType = TypeResolutionUtils.ResolveType(this.keyTypeName);
            }

            Type valueType = null;
            if (StringUtils.HasText(this.valueTypeName))
            {
                valueType = TypeResolutionUtils.ResolveType(this.valueTypeName);
            }

            if ((keyType == null) && (valueType == null))
            {
                dictionary = new HybridDictionary();
            }
            else
            {
                Type type = typeof(Dictionary<,>);
                Type[] genericArgs = new Type[2] { 
                    (keyType == null) ? typeof(object) : keyType,
                    (valueType == null) ? typeof(object) : valueType };
                type = type.MakeGenericType(genericArgs);

                dictionary = (IDictionary)ObjectUtils.InstantiateType(type);
            }

            foreach (object key in this.Keys)
			{
				string elementName = string.Format(CultureInfo.InvariantCulture, "{0}[{1}]", propertyName, key);
				object resolvedKey = resolver(objectName, definition, elementName, key);
				object resolvedValue = resolver(objectName, definition, elementName, this[key]);

                if (keyType != null)
                {
                    try
                    {
                        resolvedKey = TypeConversionUtils.ConvertValueIfNecessary(keyType, resolvedKey, propertyName);
                    }
                    catch (TypeMismatchException)
                    {
                        throw new TypeMismatchException(
                            String.Format(
                                    "Unable to convert managed dictionary key '{0}' from [{1}] into [{2}] during initialization"
                                    + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?", 
                                    resolvedKey, resolvedKey.GetType(), keyType, propertyName, objectName));
                    }
                }

                if (valueType != null)
                {
                    try
                    {
                        resolvedValue = TypeConversionUtils.ConvertValueIfNecessary(valueType, resolvedValue, propertyName + "[" + resolvedKey + "]");
                    }
                    catch (TypeMismatchException)
                    {
                        throw new TypeMismatchException(
                           String.Format(
                                   "Unable to convert managed dictionary value '{0}' from [{1}] into [{2}] during initialization"
                                   + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?", 
                                   resolvedValue, resolvedValue.GetType(), valueType, propertyName, objectName));
                    }
                }

                dictionary.Add(resolvedKey, resolvedValue);
			}

            return dictionary;
		}
Пример #5
0
        /// <summary>
        /// Resolves this managed collection at runtime.
        /// </summary>
        /// <param name="objectName">
        /// The name of the top level object that is having the value of one of it's
        /// collection properties resolved.
        /// </param>
        /// <param name="definition">
        /// The definition of the named top level object.
        /// </param>
        /// <param name="propertyName">
        /// The name of the property the value of which is being resolved.
        /// </param>
        /// <param name="resolver">
        /// The callback that will actually do the donkey work of resolving
        /// this managed collection.
        /// </param>
        /// <returns>A fully resolved collection.</returns>
        public ICollection Resolve(string objectName, IObjectDefinition definition, string propertyName, ManagedCollectionElementResolver resolver)
        {
            ISet set = new HybridSet();
            
            Type elementType = null;
            if (StringUtils.HasText(this.elementTypeName))
            {
                elementType = TypeResolutionUtils.ResolveType(this.elementTypeName);
            }

            string elementName = propertyName + "[(set-element)]";
            foreach (object element in this)
            {
                object resolvedElement = resolver(objectName, definition, elementName, element);

                if (elementType != null)
                {
                    try
                    {
                        resolvedElement = TypeConversionUtils.ConvertValueIfNecessary(elementType, resolvedElement, propertyName);
                    }
                    catch (TypeMismatchException)
                    {
                        throw new TypeMismatchException(
                            String.Format(
                                    "Unable to convert managed set element '{0}' from [{1}] into [{2}] during initialization"
                                    + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?", 
                                    resolvedElement, resolvedElement.GetType(), elementType, propertyName, objectName));
                    }
                }

                set.Add(resolvedElement);
            }

            return set;
        }
Пример #6
0
        /// <summary>
        /// Resolves this managed collection at runtime.
        /// </summary>
        /// <param name="objectName">
        /// The name of the top level object that is having the value of one of it's
        /// collection properties resolved.
        /// </param>
        /// <param name="definition">
        /// The definition of the named top level object.
        /// </param>
        /// <param name="propertyName">
        /// The name of the property the value of which is being resolved.
        /// </param>
        /// <param name="resolver">
        /// The callback that will actually do the donkey work of resolving
        /// this managed collection.
        /// </param>
        /// <returns>A fully resolved collection.</returns>
        public ICollection Resolve(string objectName, IObjectDefinition definition, string propertyName, ManagedCollectionElementResolver resolver)
        {
            ISet set = new HybridSet();

            Type elementType = null;

            if (StringUtils.HasText(this.elementTypeName))
            {
                elementType = TypeResolutionUtils.ResolveType(this.elementTypeName);
            }

            string elementName = propertyName + "[(set-element)]";

            foreach (object element in this)
            {
                object resolvedElement = resolver(objectName, definition, elementName, element);

                if (elementType != null)
                {
                    try
                    {
                        resolvedElement = TypeConversionUtils.ConvertValueIfNecessary(elementType, resolvedElement, propertyName);
                    }
                    catch (TypeMismatchException)
                    {
                        throw new TypeMismatchException(
                                  String.Format(
                                      "Unable to convert managed set element '{0}' from [{1}] into [{2}] during initialization"
                                      + " of property '{3}' for object '{4}'. Do you have an appropriate type converter registered?",
                                      resolvedElement, resolvedElement.GetType(), elementType, propertyName, objectName));
                    }
                }

                set.Add(resolvedElement);
            }

            return(set);
        }
Пример #7
0
 public ICollection Resolve(string objectName, IObjectDefinition definition, string propertyName, ManagedCollectionElementResolver resolver)
 {
     throw new NotImplementedException();
 }
 public ICollection Resolve(string objectName, IObjectDefinition definition, string propertyName, ManagedCollectionElementResolver resolver)
 {
     throw new NotImplementedException();
 }