VOOZH about

URL: https://www.nuget.org/packages/ReflectionMagic/

⇱ NuGet Gallery | ReflectionMagic 5.0.1




ReflectionMagic 5.0.1

dotnet add package ReflectionMagic --version 5.0.1
 
 
NuGet\Install-Package ReflectionMagic -Version 5.0.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="ReflectionMagic" Version="5.0.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ReflectionMagic" Version="5.0.1" />
 
Directory.Packages.props
<PackageReference Include="ReflectionMagic" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ReflectionMagic --version 5.0.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ReflectionMagic, 5.0.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.
#:package ReflectionMagic@5.0.1
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ReflectionMagic&version=5.0.1
 
Install as a Cake Addin
#tool nuget:?package=ReflectionMagic&version=5.0.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

ReflectionMagic

👁 Build Status

Private reflection allows you to access private and internal members in other assemblies. Generally, it’s considered to be a bad thing to do, as it ties you to undocumented implementation details which can later break you. Also, it’s not usable in medium trust.

The purpose of this library is not to encourage anyone to use private reflection in situations where you would not have done it anyway. Instead, the purpose is to allow you to do it much more easily if you decide that you need to use it.

Putting it a different way, I’m not telling you to break the law, but I’m telling you how to break the law more efficiently if that’s what you’re into!

The scenario

Assume you are using an assembly that has code like this:

public class Foo1 
{
 private Foo2 GetOtherClass() 
 { 
 // Omitted
 }
}

internal class Foo2 
{
 private string SomeProp { get { /* Omitted */ } }
}

And assume you have an instance foo1 of the public class Foo1 and your evil self tells you that you want to call the private method GetOtherClass() and then get the SomeProp property off that.

Using reflection

Using plain old reflection this would be something like this:

object foo2 = typeof(Foo1).InvokeMember("GetOtherClass", 
 BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod,
 null, foo1, null);
 
PropertyInfo propInfo = foo2.GetType().GetProperty("SomeProp", 
 BindingFlags.Instance | BindingFlags.NonPublic);

string val = (string)propInfo.GetValue(foo2, null);

Which works, but is pretty ugly.

Using ReflectionMagic

Doing the same but using the ReflectionMagic library:

string val = foo1.AsDynamic().GetOtherClass().SomeProp;

Download

This library is available through NuGet.

More info

For more information look at the original blog post by David Ebbo: https://blogs.msdn.microsoft.com/davidebb/2010/01/18/use-c-4-0-dynamic-to-drastically-simplify-your-private-reflection-code/

Known limitations

Support for 'out' and 'ref' parameters is not available on .NET Core 1.x runtimes. This is a runtime limitation and results in a PlatformNotSupportedException.

Product Versions Compatible and additional computed target framework versions.
.NET net5.0 net5.0 was computed.  net5.0-windows net5.0-windows was computed.  net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 was computed.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
.NET Core netcoreapp2.0 netcoreapp2.0 was computed.  netcoreapp2.1 netcoreapp2.1 was computed.  netcoreapp2.2 netcoreapp2.2 was computed.  netcoreapp3.0 netcoreapp3.0 was computed.  netcoreapp3.1 netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 netstandard2.0 is compatible.  netstandard2.1 netstandard2.1 was computed. 
.NET Framework net461 net461 was computed.  net462 net462 is compatible.  net463 net463 was computed.  net47 net47 was computed.  net471 net471 was computed.  net472 net472 was computed.  net48 net48 was computed.  net481 net481 was computed. 
MonoAndroid monoandroid monoandroid was computed. 
MonoMac monomac monomac was computed. 
MonoTouch monotouch monotouch was computed. 
Tizen tizen40 tizen40 was computed.  tizen60 tizen60 was computed. 
Xamarin.iOS xamarinios xamarinios was computed. 
Xamarin.Mac xamarinmac xamarinmac was computed. 
Xamarin.TVOS xamarintvos xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (27)

Showing the top 5 NuGet packages that depend on ReflectionMagic:

Package Downloads
Lime.Transport.WebSocket

C# LIME web socket transport library

RazorGenerator.Testing

Helpers to allow unit testing precompiled Razor views

Wyam.Less

Wyam is a simple to use, highly modular, and extremely configurable static content generator. This library provides support for parsing Less CSS content.

FakeLocalTimeZone

Create fake of local TimeZone

Kledex

Kledex is a .NET Core framework that can be used to create a simple and clean design by enforcing single responsibility and separation of concerns. Its advanced features are ideal for Domain Driven Design (DDD), Command Query Responsibilty Segragation (CQRS) and Event Sourcing. Kledex also has Azure Service Bus and RabbitMQ integrations.

GitHub repositories (11)

Showing the top 11 popular GitHub repositories that depend on ReflectionMagic:

Repository Stars
testcontainers/testcontainers-dotnet
A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
rnwood/smtp4dev
smtp4dev - the fake smtp email server for development and testing
UiPath/CoreWF
WF runtime ported to work on .NET 6
CodeMazeBlog/CodeMazeGuides
The main repository for all the Code Maze guides
RazorGenerator/RazorGenerator
A Custom Tool for Visual Studio that allows processing Razor files at design time instead of runtime, allowing them to be built into an assembly for simpler reuse and distribution.
daveaglick/FluentBootstrap
Provides extensions, helper classes, model binding, and other goodies to help you use the Bootstrap CSS framework from .NET code.
Wyamio/Wyam
A modular static content and static site generator.
joelday/papyrus-lang
📜Advanced language tools for the Papyrus scripting language.
osstotalsoft/nbb
.Net Building Blocks
surveysolutions/surveysolutions
Survey Solutions is a survey management and data collection system developed by the World Bank.
takenet/lime-csharp
C# LIME protocol implementation
Version Downloads Last Updated
5.0.1 594,738 1/29/2024
5.0.0 230,867 6/9/2023
4.1.0 3,729,752 6/24/2019
4.1.0-beta1 1,325 6/17/2019
4.0.0 148,830 11/15/2018
4.0.0-beta1 1,515 9/10/2018
3.2.0-beta1 4,925 5/29/2018
3.1.0 573,256 11/13/2017
3.1.0-beta1 1,822 11/1/2017
3.0.0 132,944 3/9/2017
3.0.0-beta5 3,031 12/27/2016
3.0.0-beta1 1,969 11/22/2016
2.1.0 121,683 12/31/2014
2.0.3 59,708 10/14/2014
2.0.2 29,114 3/7/2014
2.0.0 228,171 4/26/2013
Loading failed