private RefType GetRefType(string definitionRef, Type paramType)
        {
            var refTypeDefinition = factory.GetObjectDefinition(definitionRef);

            if (refTypeDefinition == null)
            {
                throw new TypeLoadException(string.Format(ErrorRefNotFound, definitionRef));
            }

            var type = AssemblyUtils.FindType(refTypeDefinition.Type);

            if (type == null)
            {
                throw new TypeLoadException(string.Format(ErrorTypeNotFound, refTypeDefinition.Type));
            }

            return(ReflectionUtils.CanCast(paramType, type) ? new RefType(definitionRef, paramType) : null);
        }
        public object Create(Type toType)
        {
            if (objectTypes == null)
            {
                //TODO: implement properly so it navigates all config types for the bestmatch (like registered providers)
                return(Create(toType.Name, toType));
            }
            var matchingTypes = objectTypes.Where(objectType => ReflectionUtils.CanCast(toType, objectType.Value)).ToList();

            if (matchingTypes.Count == 0)
            {
                return(null);
            }
            if (matchingTypes.Count > 1)
            {
                throw new AmbiguousMatchException(
                          string.Format("There are '{0}' possible matches available for type '{1}'. You must reference ambiguous matches by name.",
                                        matchingTypes.Count, toType.FullName));
            }
            return(Create(matchingTypes[0].Key, toType));
        }