static class · System

Activator

public static class Activator

Objects of types known at run time.

Tipo
static class
Espacio de nombres
System
Ensamblado
System.Core
Acceso
public, static, abstract
Archivo fuente
Reflection.ant

Herencia

Clases base
Any Activator

Métodos

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.

Miembros privados e internos (1)

any?[] None
#

internal static

No arguments.

Miembros heredados (5)

Código fuente

Activator en Antril, descompilado a partir de su 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