DynamicReflector 2023.3.20.1

dotnet add package DynamicReflector --version 2023.3.20.1
NuGet\Install-Package DynamicReflector -Version 2023.3.20.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DynamicReflector" Version="2023.3.20.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DynamicReflector --version 2023.3.20.1
#r "nuget: DynamicReflector, 2023.3.20.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DynamicReflector as a Cake Addin
#addin nuget:?package=DynamicReflector&version=2023.3.20.1

// Install DynamicReflector as a Cake Tool
#tool nuget:?package=DynamicReflector&version=2023.3.20.1

DynamicReflector

DynamicReflector is a C# library that provides an easy way to access fields and methods on objects and static classes using dynamic and reflection.

Powered by Traverse from Harmony by Andreas Pardeike.

How it works

The Reflector object binds to another object and uses reflection to access its fields and methods.

When you access a member of the Reflector dynamic object, a new Reflector object is returned that is bound to the resulting object.

// dynamic reflector
dynamic fieldReflection = reflector.filed;
dynamic methodReflection =  reflector.method();

When you write to a member of the Reflector dynamic object, the value is written directly to the bound object.

// dynamic reflector
reflector.filed = 7; // changes binded object filed value

Installation

Install nuget packet

via dotnet

dotnet add package DynamicReflector

via nuget

Install-Package DynamicReflector

Usage

// Getting reflector for an object
object obj = new InternalClass();
dynamic reflector = obj.ToReflector();

// ... or using new()
dynamic reflectorNew = new Reflector(obj);

// ... or using Create()
dynamic reflectorCreate = Reflector.Create(typeof(InternalClass), 1337);

// Getting private field value
// We need to explisitly cast OriginalObject to desired type
var value = (int)reflector.value.OriginalObject;

// Setting private field value
reflector.value = 7; // changes obj.value

// Call a method and get the result
var result = (int)reflector.ReturnValue().OriginalObject;

// Creating reflector for a class to call static methods
dynamic staticReflector = Reflector.CreateStatic(typeof(InternalClass));

// Call static method
var staticMethodResult = staticReflector.StaticMethod().OriginalObject;

Where InternalClass is:

internal class InternalClass
{
    private int value;

    private static string StaticMethod()
    {
        return "static";
    }

    public InternalClass() 
        : this(0)
    {
    }

    private InternalClass(int value)
    {
        this.value = value;
    }

    private int ReturnValue()
    {
        return this.value;
    }
}
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2023.3.20.1 204 3/20/2023
2023.3.16.1 175 3/16/2023