VOOZH about

URL: https://www.nuget.org/packages/Detached.RuntimeTypes/

⇱ NuGet Gallery | Detached.RuntimeTypes 8.0.0




👁 Image
Detached.RuntimeTypes 8.0.0

dotnet add package Detached.RuntimeTypes --version 8.0.0
 
 
NuGet\Install-Package Detached.RuntimeTypes -Version 8.0.0
 
 
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="Detached.RuntimeTypes" Version="8.0.0" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Detached.RuntimeTypes" Version="8.0.0" />
 
Directory.Packages.props
<PackageReference Include="Detached.RuntimeTypes" />
 
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 Detached.RuntimeTypes --version 8.0.0
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Detached.RuntimeTypes, 8.0.0"
 
 
#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 Detached.RuntimeTypes@8.0.0
 
 
#: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=Detached.RuntimeTypes&version=8.0.0
 
Install as a Cake Addin
#tool nuget:?package=Detached.RuntimeTypes&version=8.0.0
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Runtime Types

What is it

This library tries to simplify the runtime type creation by adding new things like the ability to define methods using Expressions and automatic interface implementation. It's a part of Detached.Mappers library. Thanks to the people who made FastExpressionCompiler, that is the core of this library.

What does it solve

It allows devs to create tools like dynamic proxies, comparers, dirty check (INotifyPropertyChange) or any other thing that may be a good fit for dynamic code without having to manually emit op codes. Methods can be defined using Expression trees.

How it works

Lets say that we want to dinamically create a type for this interface:

 public interface ISumService
 {
 int Sum(int a, int b);
 }

Then we need to intialize a type builder, define an implementation for Sum method using an expression tree, and call AutoImplementInterface to perform the override.

// create a type builder, this will handle the creation of a new Type.
RuntimeTypeBuilder typeBuilder = new RuntimeTypeBuilder("MyISumServiceImplementation", typeof(BasePropertyClass));

// define the parameters expected by the interface method.
var aParam = Parameter(typeof(int), "a");
var bParam = Parameter(typeof(int), "b");

// define a mehtod with the same signature (name and parameters),
// use "Add" expression as the method body
typeBuilder.DefineMethod(
 "Sum",
 new[] { aParam, bParam },
 Block(
 Add(aParam, bParam)
 )
);
 
// implement the interface, this will iterate over all methods and 
// call DefineMethodOverride to bind the existing methods to the given 
// interface methods
typeBuilder.AutoImplementInterface(typeof(ISumService));

// create the type that will be used to initialize new instances of ISumService
Type myISumServiceType = typeBuilder.Create();

// create an instance of our dynamic ISumService implementation
ISumService myISumService = (ISumService)Activator.CreateInstance(myISumServiceType);

// test the implementation
Assert.Equal(14, myISumService.Sum(5, 9));

More info and examples will be added later. Check unit tests for more samples!

Product Versions Compatible and additional computed target framework versions.
.NET 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 is compatible.  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 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Detached.RuntimeTypes:

Package Downloads
Detached.Mappers

A general purpose object-oriented mapper.

Detached.PatchTypes

Allows to create a proxy type of a given DTO that implements IPatch interface and allows to check for dirty (or set) properies. It also provides a JsonConverter that handles IPatch types. This library is a part of Detached.Mappers.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on Detached.RuntimeTypes:

Repository Stars
leonardoporro/Detached-Mapper
An ORM friendly mapper. Allows saving entire entity graphs. Heavily inspired in GraphDiff and AutoMapper.
Version Downloads Last Updated
8.0.0 13,224 1/22/2024
7.0.13 218 1/22/2024
7.0.4 253 1/22/2024
6.0.5 885 1/1/2023
6.0.3 492 1/1/2023
1.0.0 234 1/22/2024