>        public static T CreateObjectFromString(string typeName, Type[]
> types, string[] paramValues)

Why not the more generic object[] for paramValues?

>   parameters[i] = Convert.ChangeType(paramValues[i],

You could use something like the ChangeType helper from
WilsonORMapper's QueryHelper to insure that more things convert
safely... here's a version of that method:

        static public object ChangeType(object value, Type type) {
                if (value == null && type.IsGenericType) return
Activator.CreateInstance(type);
                if (value == null) return null;
                if (type == value.GetType()) return value;

                if (type.IsEnum) {
                        if (value is string)
                                return Enum.Parse (type, value as string);
                        else
                                return Enum.ToObject(type, value);
                }

                if (!type.IsInterface && type.IsGenericType) {
                        Type innerType = type.GetGenericArguments()[0];
                        object innerValue = QueryHelper.ChangeType(value, 
innerType);
                        return Activator.CreateInstance(type, new object[] { 
innerValue });
                }

                if (value is string && type == typeof(Guid)) return new 
Guid(value as string);
                if (value is string && type == typeof(Version)) return new
Version(value as string);
                if (!(value is IConvertible)) return value;
                return Convert.ChangeType(value, type);
        }

--
"Under capitalism, man exploits man. Under communism, it's just the
opposite."  –John Kenneth Gailbraith

Marc C. Brooks
mailto:[EMAIL PROTECTED]
http://musingmarc.blogspot.com

Reply via email to