static class · System

Activator

public static class Activator

Objects of types known at run time.

Kind
static class
Namespace
System
Assembly
System.Core
Access
public, static, abstract
Source file
Reflection.ant

Inheritance

Base classes
Any Activator

Methods

CreateInstance(Type type) : any
#

static

A new object of type through its constructor without parameters (a value type's zero value when it has none).

CreateInstance(Type type, any?[] arguments) : any
#

static

A new object of type through the public constructor that takes arguments.

Private and internal members (1)

any?[] None
#

internal static

No arguments.

Inherited members (5)

Source

Activator as Antril, decompiled from its Larva HIR.

System.Activator.ant
// System.Activator — System.Core (decompiled from Larva HIR)

import System.Reflection;

into namespace System
{
	/// Objects of types known at run time.
	public static class Activator
	{
		internal:
			/// No arguments.
			any?[] None;

		public:
			/// A new object of `type` through its constructor without parameters (a value type's zero value when it has none).
			CreateInstance(Type type) : any
			{
				if (type.PlainConstructor() is ConstructorInfo plain)
					return plain.Describer.Construct(plain.Index, None);
				return CreateInstance(type, None);
			}

			/// A new object of `type` through the public constructor that takes `arguments`.
			CreateInstance(Type type, any?[] arguments) : any
			{
				{
					ConstructorInfo[] _items0 = type.GetConstructors();
					i32 _index1 = 0;
					loop (_index1 < _items0.Length)
					{
						ConstructorInfo c = _items0[_index1];
						{
							if (c.Accepts(arguments))
								return c.Invoke(arguments);
						}
						_index1++;
					}
				}
				if (arguments.Length == 0 && type.IsValueType)
					return type.ZeroValue();
				throw new MissingMemberError(type.FullName + " has no public constructor that takes these arguments");
			}
	}
}
Esc