Spring.Objects.Factory.Config.ManagedList.Resolve C# (CSharp) Method

Resolve() public method

Resolves this managed collection at runtime.
public Resolve ( string objectName, IObjectDefinition definition, string propertyName, ManagedCollectionElementResolver resolver ) : ICollection
objectName string /// The name of the top level object that is having the value of one of it's /// collection properties resolved. ///
definition IObjectDefinition /// The definition of the named top level object. ///
propertyName string /// The name of the property the value of which is being resolved. ///
resolver ManagedCollectionElementResolver /// The callback that will actually do the donkey work of resolving /// this managed collection. ///
return ICollection
        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;
        }