Open sandboxFocus

Method AddInitializer

AddInitializer(IAdviser<INamedType>, string, InitializerKind, object?, object?)

Adds a type or instance initializer by using a template. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

Declaration
public static IAddInitializerAdviceResult AddInitializer(this IAdviser<INamedType> adviser, string template, InitializerKind kind, object? args = null, object? tags = null)
Parameters
Type Name Description
IAdviser<INamedType> adviser

An adviser for a named type.

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 args

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

object tags

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

Returns
Type Description
IAddInitializerAdviceResult

AddInitializer(IAdviser<INamedType>, IStatement, InitializerKind)

Adds a type or instance initializer by specifying an IStatement. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

Declaration
public static IAddInitializerAdviceResult AddInitializer(this IAdviser<INamedType> adviser, IStatement statement, InitializerKind kind)
Parameters
Type Name Description
IAdviser<INamedType> adviser

An adviser for a named type.

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(IAdviser<IConstructor>, string, object?, object?)

Adds an initializer to a specific constructor by using a template. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

Declaration
public static IAddInitializerAdviceResult AddInitializer(this IAdviser<IConstructor> adviser, string template, object? args = null, object? tags = null)
Parameters
Type Name Description
IAdviser<IConstructor> adviser

An adviser for a constructor.

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 args

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

object tags

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

Returns
Type Description
IAddInitializerAdviceResult

AddInitializer(IAdviser<IConstructor>, IStatement)

Adds an initializer to a specific constructor by specifying an IStatement. Use the With<TNewDeclaration>(TNewDeclaration) method to apply the advice to another declaration than the current one.

Declaration
public static IAddInitializerAdviceResult AddInitializer(this IAdviser<IConstructor> adviser, IStatement statement)
Parameters
Type Name Description
IAdviser<IConstructor> adviser

An adviser for a constructor.

IStatement statement

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

Returns
Type Description
IAddInitializerAdviceResult