MixedIL.Fody
0.1.6
See the version list below for details.
dotnet add package MixedIL.Fody --version 0.1.6
NuGet\Install-Package MixedIL.Fody -Version 0.1.6
<PackageReference Include="MixedIL.Fody" Version="0.1.6" />
paket add MixedIL.Fody --version 0.1.6
#r "nuget: MixedIL.Fody, 0.1.6"
// Install MixedIL.Fody as a Cake Addin #addin nuget:?package=MixedIL.Fody&version=0.1.6 // Install MixedIL.Fody as a Cake Tool #tool nuget:?package=MixedIL.Fody&version=0.1.6
MixedIL.Fody
This is an add-in for Fody which allows you to impliment C# method by IL code.
Installation
Include the
Fody
andMixedIL.Fody
NuGet packages with aPrivateAssets="all"
attribute on their<PackageReference />
items. InstallingFody
explicitly is needed to enable weaving.<PackageReference Include="Fody" Version="..." PrivateAssets="all" /> <PackageReference Include="MixedIL.Fody" Version="..." PrivateAssets="all" />
If you already have a
FodyWeavers.xml
file in the root directory of your project, add the<MixedIL />
tag there. This file will be created on the first build if it doesn't exist:<?xml version="1.0" encoding="utf-8" ?> <Weavers> <MixedIL /> </Weavers>
See Fody usage for general guidelines, and Fody Configuration for additional options.
Usage
- Write a method stub in a C# project with keyword
extern
and an attribute provided inMixedIL
calledMixedILAttribute
using MixedIL;
namespace System;
public class ObjectHelper
{
[MixedIL]
public static extern bool AreSame<T>(ref T a, ref T b);
}
- Then create a .il file in the the C# project and implement the method in il code. C# dll
.class public abstract auto ansi sealed beforefieldinit System.ObjectHelper
{
.method public hidebysig static bool AreSame<T>(!!T& a, !!T& b) cil managed aggressiveinlining
{
.maxstack 2
ldarg.0
ldarg.1
ceq
ret
}
}
- Compile the project and that's it.
NOTE:
- The method signature and declaring type should be the same.
- Only il method body will be injected into the assembly file, other parts like attributes in il code won't. You can just write all the other parts using C# code.
Examples
- An example project
- A reimplementation of the
System.Runtime.CompilerServices.Unsafe
called MixedIL.Unsafe is provided as an example.
Comparison with InlineIL.Fody
InlineIL.Fody is a remarkable fody add-in which lets you inject IL instructions by calling normal static C# methods. While there are some differences, so you can choose based on your requirement.
- Basically, in most cases you can use
InlineIL
, which is more friendly to C# developers. MixedIL
is more flexible and less restrictive, since pure IL code will be written.
For instance, you can invoke backing field of a property without setter by pure IL, like this:
stfld string [System.Runtime]System.Reflection.AssemblyKeyNameAttribute::'<KeyName>k__BackingField'
see example code.
However, up to now, you will get compile error if you would like to implement it usingInlineIL
.
Product | Versions 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Fody (>= 6.8.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.