Table of Contents

Class ExtensionToInstanceProxy

Namespace
Dynamitey.DynamicObjects
Assembly
Dynamitey.Community.dll

Proxy that can turn extension methods into instance methods

public class ExtensionToInstanceProxy : BaseForwarder, IDynamicMetaObjectProvider, IEquivalentType, IForwarder
Inheritance
ExtensionToInstanceProxy
Implements
Derived
Inherited Members

Constructors

ExtensionToInstanceProxy(dynamic, Type, Type[], Type[]?)

Initializes a new instance of the ExtensionToInstanceProxy class.

[RequiresUnreferencedCode("Calls IsExtendedType, which reflects over target's interfaces (GetInterfaces) to check it against extendedType; trimming can remove an interface this depends on. target is also statically 'dynamic', which forces DLR binding on the IsExtendedType calls below even though that method takes a plain object.")]
[RequiresDynamicCode("Constructing any BaseForwarder-derived type instantiates System.Dynamic.DynamicObject, whose default constructor requires the DLR's runtime code generation; not supported when AOT-compiled.")]
public ExtensionToInstanceProxy(dynamic target, Type extendedType, Type[] staticTypes, Type[]? instanceHints = null)

Parameters

target dynamic

The target.

extendedType Type

Type of the extended.

staticTypes Type[]

The static types.

instanceHints Type[]

The instance hints.

Exceptions

ArgumentException

Don't Nest ExtensionToInstance Objects

Properties

InstanceHints

Gets the instance hints.

public IEnumerable<Type>? InstanceHints { get; }

Property Value

IEnumerable<Type>

The instance hints.

Methods

CreateSelf(object, Type, Type[], Type[]?)

Creates the self.

[RequiresUnreferencedCode("Constructs the annotated ExtensionToInstanceProxy.")]
[RequiresDynamicCode("Constructs the annotated ExtensionToInstanceProxy, which requires the DLR's runtime code generation.")]
protected virtual ExtensionToInstanceProxy CreateSelf(object target, Type extendedType, Type[] staticTypes, Type[]? instanceHints)

Parameters

target object

The target.

extendedType Type

Type of the extended.

staticTypes Type[]

The static types.

instanceHints Type[]

The instance hints.

Returns

ExtensionToInstanceProxy

InvokeStaticMethod(String_OR_InvokeMemberName, object?[])

Invokes the static method.

[RequiresUnreferencedCode("Reflects over target's interfaces (GetInterfaces) for generic-argument resolution and calls the annotated Dynamic.InvokeMember/CreateSelf; trimming can remove a member either depends on.")]
[RequiresDynamicCode("Dynamic.InvokeMember binds through the DLR, which requires runtime code generation; not supported when AOT-compiled.")]
protected object? InvokeStaticMethod(String_OR_InvokeMemberName name, object?[] args)

Parameters

name String_OR_InvokeMemberName

The name.

args object[]

The args.

Returns

object

TryGetMember(GetMemberBinder, out object?)

Provides the implementation for operations that get member values. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations such as getting a value for a property.

[UnconditionalSuppressMessage("Trimming", "IL2075", Justification = "Reflects over the (unwrapped) target's interfaces to build an Invoker for the extended-method binder.Name. 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("Trimming", "IL2026", Justification = "Constructs the annotated Invoker. Same DynamicObject.TryGetMember override reasoning as the IL2075 suppression above.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Same Invoker construction as above; see the IL2075/IL2026 suppressions 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?)

Tries the invoke member.

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Calls the annotated Dynamic.InvokeGet (to read the binder's own generic-arguments property by name) and the annotated InvokeStaticMethod. 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 calls as above; see the IL2026 suppression on this member.")]
public override bool TryInvokeMember(InvokeMemberBinder binder, object?[]? args, out object? result)

Parameters

binder InvokeMemberBinder

The binder.

args object[]

The args.

result object

The result.

Returns

bool