/// <summary> /// Creates the object of the specified type. /// </summary> /// <param name="typeName">The type of the created object.</param> /// <returns>The Created object.</returns> public static object CreateObject(string typeName, object[] arguments) { Type type = StiTypeFinder.GetType(typeName); if (type != null) { try { return(Activator.CreateInstance(type, arguments)); } catch (Exception exp) { Exception e = exp.InnerException != null ? exp.InnerException : exp; throw e; } } else { if (AllowTypeNotFoundException) { throw new Exception("The type " + typeName + " not found!"); } else { return(null); } } }
/// <summary> /// Convertes string into object. /// </summary> /// <param name="str">String that represents object.</param> /// <param name="type">Object type.</param> /// <returns>Converted object.</returns> public virtual object StringToObject(string str, Type type) { if (type == typeof(string)) { return(str); } else if (type == typeof(decimal)) { return(decimal.Parse(str)); } else if (type == typeof(Type)) { Type tp = StiTypeFinder.GetType(str); if (tp != null) { return(tp); } var assemblys = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assembly in assemblys) { tp = assembly.GetType(str); if (tp != null) { return(tp); } } if (tp == null) { throw new TypeLoadException("Type \"" + str + "\" not found"); } return(null); } if (type == typeof(object)) { return(str); } TypeConverter converter = TypeDescriptor.GetConverter(type); return(converter.ConvertFromString(str)); }