System.Reflection.Assembly.CreateInstance C# (CSharp) Method

CreateInstance() private method

private CreateInstance ( string typeName ) : object
typeName string
return object
        public extern object CreateInstance(string typeName);

Usage Example

Esempio n. 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public static object CreateClassInstance(Assembly assembly, string className, object[] args)
		{
			try
			{
				// First, take a stab at creating the instance with the specified name.
				object instance = assembly.CreateInstance(className, false,
					BindingFlags.CreateInstance, null, args, null, null);

				if (instance != null)
					return instance;

				Type[] types = assembly.GetTypes();

				// At this point, we know we failed to instantiate a class with the
				// specified name, so try to find a type with that name and attempt
				// to instantiate the class using the full namespace.
				foreach (Type type in types)
				{
					if (type.Name == className)
					{
						return assembly.CreateInstance(type.FullName, false,
							BindingFlags.CreateInstance, null, args, null, null);
					}
				}
			}
			catch { }

			return null;
		}
All Usage Examples Of System.Reflection.Assembly::CreateInstance