Metalama 1.0 / / Metalama Documentation / Aspect API Documentation / Metalama.​Framework.​Advising / IAdvice­Factory / Add­Initializer

Method AddInitializer

AddInitializer(INamedType, String, InitializerKind, Object, Object)

Adds a type or instance initializer by using a template.

Declaration
IAddInitializerAdviceResult AddInitializer(INamedType targetType, string template, InitializerKind kind, object tags = null, object args = null)
Parameters
Type Name Description
INamedType targetType

The type into which the initializer should be added.

String template

The name of the template. This method must have no run-time parameter, be of void return type, and be annotated with the TemplateAttribute custom attribute.

InitializerKind kind

The type of initializer to add.

Object tags

An optional opaque object of anonymous type passed to templates and exposed under the Tags property of the meta API.

Object args

An object (typically of anonymous type) whose properties map to parameters or type parameters of the template.

Returns
Type Description
IAddInitializerAdviceResult

AddInitializer(INamedType, IStatement, InitializerKind)

Adds a type or instance initializer by specifying an IStatement.

Declaration
IAddInitializerAdviceResult AddInitializer(INamedType targetType, IStatement statement, InitializerKind kind)
Parameters
Type Name Description
INamedType targetType

The type into which the initializer should be added.

IStatement statement

The statement to be inserted at the top of constructors.

InitializerKind kind

The type of initializer to add.

Returns
Type Description
IAddInitializerAdviceResult

AddInitializer(IConstructor, String, Object, Object)

Adds an initializer to a specific constructor by using a template.

Declaration
IAddInitializerAdviceResult AddInitializer(IConstructor targetConstructor, string template, object tags = null, object args = null)
Parameters
Type Name Description
IConstructor targetConstructor

The constructor into which the initializer should be added.

String template

The name of the template. This method must have no run-time parameter, be of void return type, and be annotated with the TemplateAttribute custom attribute.

Object tags

An optional opaque object of anonymous type passed to templates and exposed under the Tags property of the meta API.

Object args

An object (typically of anonymous type) whose properties map to parameters or type parameters of the template.

Returns
Type Description
IAddInitializerAdviceResult

AddInitializer(IConstructor, IStatement)

Adds an initializer to a specific constructor by specifying an IStatement.

Declaration
IAddInitializerAdviceResult AddInitializer(IConstructor targetConstructor, IStatement statement)
Parameters
Type Name Description
IConstructor targetConstructor

The constructor into which the initializer should be added.

IStatement statement

The statement to be inserted at the top of the constructor.

Returns
Type Description
IAddInitializerAdviceResult