AttainGroup.Library.ILGenerator 1.0.0

dotnet add package AttainGroup.Library.ILGenerator --version 1.0.0
                    
NuGet\Install-Package AttainGroup.Library.ILGenerator -Version 1.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="AttainGroup.Library.ILGenerator" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AttainGroup.Library.ILGenerator" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AttainGroup.Library.ILGenerator" />
                    
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 AttainGroup.Library.ILGenerator --version 1.0.0
                    
#r "nuget: AttainGroup.Library.ILGenerator, 1.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 AttainGroup.Library.ILGenerator@1.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=AttainGroup.Library.ILGenerator&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AttainGroup.Library.ILGenerator&version=1.0.0
                    
Install as a Cake Tool

DynamicIL

With the Package, DynamicIL (MIT Licence) types can be created during runtime using the Reflection Emit Library. Works with .net Full Framework and also with .net Core.

Important in this context is, that you have to know, how you can create dynamic code in .net. There are different approaches:

  • Creating and Compiling Code
  • Emit Objects with Code with IL Emit
  • Use the .net Scripting Engine (ex. Ironpython)

With creating and compiling code at runtime, you can get results very fast. But, the compile process is not the fastest. If you use the .net scripting engine, you can change the code during runtime, because it is only interpreted.

This Library uses a completely different way: it builds objects with .net Emit, where the IL Code is generated during runtime, and, in full framework environments it can be saved to disk for reusing the results.

The advantage of generating the code with IL: it is fast. And the result can be taken from any library via reflection. If you want to build a Webservice on the fly, generating or parsing json, this is an interesting option. An interesting possible use case is, to save the structure of objects in a database, add a bit of logic and create by this way a complete Business Layer.

Example of creating a simple Type with the INotifyPropertyChanged Interface:

CustomTypeCreator ct = new CustomTypeCreator("testassembly");
var cPerson = ct.CreateNewNotifyPropertyChangedType("Person");
cPerson.AddProperty("FirstName", typeof(string));
cPerson.AddProperty("LastName", typeof(string));
cPerson.AddProperty("Uid", typeof(Guid));

var types = ct.Build();
var tPerson = types.FirstOrDefault(w => w.Name == "Person");

var iPerson = tPerson.CreateInstanceWithPropertyGetAndSet() as BaseClasses.NotifyPropertyChangedBase;
var hadChanges = false;
iPerson.PropertyChanged += (s, a) => {
    hadChanges = true;
};

Guid guid = Guid.NewGuid();


iPerson.SetPropertyValue("FirstName", "Lukas");
iPerson.SetPropertyValue("LastName", "Dorn-Fussenegger");
iPerson.SetPropertyValue("Uid", guid);


Assert.IsTrue(iPerson.GetPropertyValue<string>("FirstName") == "Lukas");
Assert.IsTrue(iPerson.GetPropertyValue<string>("LastName") == "Dorn-Fussenegger");
Assert.IsTrue(iPerson.GetPropertyValue<Guid>("Uid") == guid);

Assert.IsTrue(hadChanges);

Example of creating simple objects:

CustomTypeCreator ct = new CustomTypeCreator("testassembly");
var cPerson = ct.CreateNewSimpleType("Person");
cPerson.AddProperty("FirstName", typeof(string));
cPerson.AddProperty("LastName", typeof(string));
cPerson.AddProperty("Uid", typeof(Guid));
cPerson.AddPropertyGetAndSet();


var types = ct.Build();
var tPerson = types.FirstOrDefault(w => w.Name == "Person");

var iPerson = tPerson.CreateInstanceWithPropertyGetAndSet();

Guid guid = Guid.NewGuid();


iPerson.SetPropertyValue("FirstName", "Lukas");
iPerson.SetPropertyValue("LastName", "Dorn-Fussenegger");
iPerson.SetPropertyValue("Uid", guid);


Assert.IsTrue(iPerson.GetPropertyValue<string>("FirstName") == "Lukas");
Assert.IsTrue(iPerson.GetPropertyValue<string>("LastName") == "Dorn-Fussenegger");
Assert.IsTrue(iPerson.GetPropertyValue<Guid>("Uid") == guid);

This library works with .net Full Framework AND .net Core. Saving Types to a DLL is only possible with the full framework. With .net Core it is only possible with an in-memory-creation.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.1 is compatible.  netcoreapp2.2 is compatible.  netcoreapp3.0 is compatible.  netcoreapp3.1 is compatible. 
.NET Framework net47 is compatible.  net471 is compatible.  net472 is compatible.  net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 2.1

    • No dependencies.
  • .NETCoreApp 2.2

    • No dependencies.
  • .NETCoreApp 3.0

    • No dependencies.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.7

    • No dependencies.
  • .NETFramework 4.7.1

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETFramework 4.8

    • 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
1.0.0 658 11/28/2020