Table of Contents

Class BaseFactory

Namespace
Dynamitey.DynamicObjects
Assembly
Dynamitey.Community.dll

Base Class for making a fluent factory using an Impromptu Interface return type.

public class BaseFactory : BaseObject, IDynamicMetaObjectProvider, IEquivalentType
Inheritance
BaseFactory
Implements
Derived
Inherited Members

Constructors

BaseFactory()

Initializes a new instance of the BaseFactory class.

[RequiresDynamicCode("Constructing any BaseObject-derived type instantiates System.Dynamic.DynamicObject, whose default constructor requires the DLR's runtime code generation; not supported when AOT-compiled.")]
public BaseFactory()

Methods

CreateType(Type, params object?[])

Constructs the type. Override for changing type initialization property changes.

[RequiresUnreferencedCode("Calls the annotated Dynamic.InvokeConstructor.")]
[RequiresDynamicCode("Dynamic.InvokeConstructor requires the DLR's runtime code generation; not supported when AOT-compiled.")]
protected virtual object? CreateType(Type type, params object?[] args)

Parameters

type Type

The type.

args object[]

The args.

Returns

object

GetInstanceForDynamicMember(string, params object?[])

Gets the instance for a dynamic member. Override for type construction behavior changes based on property name.

[RequiresUnreferencedCode("Calls TryTypeForName (reflects over EquivalentType's members by name) and the annotated CreateType.")]
[RequiresDynamicCode("CreateType requires the DLR's runtime code generation; not supported when AOT-compiled.")]
protected virtual object? GetInstanceForDynamicMember(string memberName, params object?[] args)

Parameters

memberName string

Name of the member.

args object[]

The args.

Returns

object

TryGetMember(GetMemberBinder, out object?)

Provides the default implementation for operations that get instance as defined by GetInstanceForDynamicMember(string, params object?[]). Classes derived from the ImpromptuInterface.ImpromptuObject class can override this method to specify dynamic behavior for operations such as getting a value for a property.

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Calls the annotated GetInstanceForDynamicMember. This is a DynamicObject.TryGetMember override: it can't carry [RequiresUnreferencedCode] itself without mismatching the unannotated base member, and the DLR invokes it only after the consumer's own dynamic member access already triggered the framework's warning.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Same GetInstanceForDynamicMember call as above; see the IL2026 suppression on this member.")]
public override bool TryGetMember(GetMemberBinder binder, out object? result)

Parameters

binder GetMemberBinder

Provides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the DynamicObject class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.

result object

The result of the get operation. For example, if the method is called for a property, you can assign the property value to result.

Returns

bool

true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a run-time exception is thrown.)

TryInvokeMember(InvokeMemberBinder, object?[]?, out object?)

Provides the implementation for operations that invoke a member. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations such as calling a method.

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Calls the annotated GetInstanceForDynamicMember. This is a DynamicObject.TryInvokeMember override: it can't carry [RequiresUnreferencedCode] itself without mismatching the unannotated base member, and the DLR invokes it only after the consumer's own dynamic call site already triggered the framework's warning.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Same GetInstanceForDynamicMember call as above; see the IL2026 suppression on this member.")]
public override bool TryInvokeMember(InvokeMemberBinder binder, object?[]? args, out object? result)

Parameters

binder InvokeMemberBinder

Provides information about the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is an instance of the class derived from the DynamicObject class, binder.Name returns "SampleMethod". The binder.IgnoreCase property specifies whether the member name is case-sensitive.

args object[]

The arguments that are passed to the object member during the invoke operation. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is derived from the DynamicObject class, args[0] is equal to 100.

result object

The result of the member invocation.

Returns

bool

true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.)