Constructor CLASS

A constructor member defined on a type.

A constructor plays the major role in initialization of an instance of a certain class. In source code, a programmer uses new operator to invoke some constructor through dynamic binding, where engine will decide in runtime the appropriate constructor to call given the arguments passed along. In contrast, this class allows calling against an exact constructor.

Parent Class

Parent Interfaces

All Members


TypeNameSignature
methodgetAttributespublic Attribute[] getAttributes()
methodgetKindpublic MemberKind getKind()
methodgetNamepublic String getName()
methodgetParameterspublic Parameter[] getParameters()
methodinvokepublic Object invoke(Any[])
methodisStaticpublic bool isStatic()
methodtoStringpublic String toString()

Methods


public Attribute[] getAttributes()

(INHERITED DOC)

Get all the attributes annotated on the member definition.

The result array contains each instance of Attribute placed at the type definition.

Returns

  • The attributes annotated on this member. In case of members which do not have attributes, this returns a 0-sized Attribute array.

public MemberKind getKind()

A constructor's kind is CONSTRUCTOR.

Returns


public String getName()

Get the name of this constructor, which is always the simple name of the class it belongs to.

Returns

  • The name of this constructor

public Parameter[] getParameters()

Get parameters of this constructor. The implicit 'this' argument is not included.

Returns


public Object invoke(var[] args)

Invoke this constructor to create a new object of the class to which the constructor belongs.

This is the programmatic way of class instantiation, which involves a series of steps similar to, but not entirely aligned with, the process initiated by new operator. Upon calling this method, the script engine will (1) allocate memory on heap for this given class
(2) initialize each instance fields by default value or initializer expressions
(3) call exactly this constructor with the object itself represented by 'this' keyword. Forwarding calls to other constructors apply.
(4) return the object

Parameters

  • args The argument array.

Returns

  • The object that has been initialized by this constructor.

Throws

  • System.Reflection.ReflectedInvocationException This exception can be thrown for a variety of reasons. If a pre-check failed on the type of arguments or calling legality (such as attempting to call a constructor of an abstract class), the exception contains the error information directly. If the constructor being invoked threw, this exception was created as a wrapper and the caller must call getCause() to get the original exception.

public bool isStatic()

A constructor is always false.

Returns

  • Always false

public String toString()

Get a string representation of this constructor member.

Returns

  • A string in form of [CTOR|ctor-signature]. ctor-signature contains constructor name and each parameter's type. Example: [CTOR|MyClass(string)]