Ryder 0.7.0
See the version list below for details.
dotnet add package Ryder --version 0.7.0
NuGet\Install-Package Ryder -Version 0.7.0
<PackageReference Include="Ryder" Version="0.7.0" />
paket add Ryder --version 0.7.0
#r "nuget: Ryder, 0.7.0"
// Install Ryder as a Cake Addin #addin nuget:?package=Ryder&version=0.7.0 // Install Ryder as a Cake Tool #tool nuget:?package=Ryder&version=0.7.0
Get started
Redirect a method
public static int Incremented(int nbr) => nbr + 1;
public static int Decremented(int nbr) => nbr - 1;
Incremented(1); // => 2.
MethodRedirection r = Redirection.Redirect<Func<int, int>>(Incremented, Decremented);
Incremented(1); // => 0.
// You can also invoke the original method:
r.InvokeOriginal(null, 1); // => 2.
// You can also stop the redirection...
r.Stop(); // or r.IsRedirecting = false, or r.Dispose().
Incremented(1); // => 2.
// ... and restart it
r.Start(); // or r.IsRedirecting = true, unless you disposed it, in which case it's no longer usable
Incremented(1); // => 0.
Using Reactive Extensions
MethodInfo method = typeof(DateTime)
.GetProperty(nameof(DateTime.Now), BindingFlags.Static | BindingFlags.Public)
.GetGetMethod();
int count = 0;
DateTime bday = new DateTime(1955, 10, 28);
// Make "DateTime.get_Now()" return "bday" every two calls.
using (Redirection.Observe(method)
.Where(_ => count++ % 2 == 0)
.Subscribe(ctx => ctx.ReturnValue = bday))
{
DateTime.Now.ShouldBe(bday);
DateTime.Now.ShouldNotBe(bday);
DateTime.Now.ShouldBe(bday);
DateTime.Now.ShouldNotBe(bday);
}
DateTime.Now.ShouldNotBe(bday);
DateTime.Now.ShouldNotBe(bday);
Other features
Any Redirection
also defines the following members:
bool IsRedirecting { get; set; }
void Start()
void Stop()
Redirections can be created in multiple ways:
MethodRedirection
:Redirect(Delegate, Delegate)
,Redirect(MethodBase, MethodBase)
.PropertyRedirection
:Redirect(PropertyInfo, PropertyInfo)
.EventRedirection
:Redirect(EventInfo, EventInfo)
.
Tests:
All features are tested in Ryder.Tests. Please check it out, as it contains some real-world-usage code.
Gloriously unsafe:
By default, Ryder performs many safety checks when you create a new Redirection
. However, should you decide to do some experimental things, disabling all those checks is as easy as setting the skipChecks
parameter available on all Redirect
methods to true
.
Implicit JIT checks:
When creating a Redirection
, Ryder will ensure that the methods you use have already been jitted. If they haven't, they will be compiled automatically.
Support for i386, x86_64, arm and arm64
Ryder is designed to work with i386
, x86_64
, arm
and arm64
using purely runtime checks. This means that it works everywhere
without additional configuration. Additionally, Windows, Linux and OSX are all supported.
Installation
You can install Ryder through the NuGet package manager:
Install-Package Ryder
Alternatively, if you don't want to add a dependency, you can copy-paste the
Ryder.Lightweight.cs
file in your project. Caution, however, since this version only provides the MethodRedirection
(simply called Redirection
), and performs no safety checks.
Additional notes
- Make sure the method you want to redirect does not get inlined by the JIT; if it does get inlined, redirecting it will most likely break stuff in unexpected ways, or do nothing at all. Additionally, if the method you redirect hasn't been jitted yet, the same problems may arise.
- In order to keep the GC from collecting jitted methods, Ryder keeps static references to them. Those references are only deleted when
Redirection.Dispose()
is called, after which theRedirection
is no longer guaranteed to work.
Inspiration
Ryder is highly inspired by Harmony, but tries to take a very minimal approach to redirection, instead of providing the ability to patch individual instructions. Moreover, it was made with .NET Core in mind.
Projects using Ryder
- The AnyConstraint analyzer uses Ryder.Lightweight to allow any constraint to be used, including
Delegate
andEnum
. - Cometary highly modifies the Roslyn compilation process in order to add custom features to C#.
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 | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net46 was computed. 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 | tizen30 was computed. tizen40 was computed. tizen60 was computed. |
Universal Windows Platform | uap was computed. uap10.0 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 1.3
- System.Collections (>= 4.3.0)
- System.Reflection.Emit.Lightweight (>= 4.3.0)
- System.Reflection.Extensions (>= 4.3.0)
- System.Reflection.TypeExtensions (>= 4.3.0)
- System.Runtime.Extensions (>= 4.3.0)
- System.Runtime.InteropServices (>= 4.3.0)
- System.Runtime.InteropServices.RuntimeInformation (>= 4.3.0)
-
.NETStandard 2.0
- System.Collections (>= 4.3.0)
- System.Reflection.Emit.Lightweight (>= 4.3.0)
- System.Reflection.Extensions (>= 4.3.0)
- System.Reflection.TypeExtensions (>= 4.3.0)
- System.Runtime.Extensions (>= 4.3.0)
- System.Runtime.InteropServices (>= 4.3.0)
- System.Runtime.InteropServices.RuntimeInformation (>= 4.3.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Ryder:
Package | Downloads |
---|---|
Cometary.Core
Core package for Cometary, required by the analyzer to edit the dependant assembly. It defines the CompilationEditor type, used to edit assemblies during compilation. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
0.8.0 | 288,231 | 4/8/2019 |
0.7.0 | 856 | 10/7/2018 |
0.6.0 | 2,571 | 11/9/2017 |
0.5.2 | 4,102 | 8/10/2017 |
0.5.1 | 906 | 8/7/2017 |
0.5.0 | 956 | 8/3/2017 |
0.4.1 | 950 | 8/2/2017 |
0.4.0 | 933 | 7/31/2017 |
0.3.5 | 936 | 7/31/2017 |
0.3.4 | 882 | 7/31/2017 |
0.3.3 | 906 | 7/31/2017 |
0.3.2 | 918 | 7/27/2017 |
0.3.1 | 908 | 7/27/2017 |
0.3.0 | 895 | 7/27/2017 |
0.2.0 | 868 | 7/26/2017 |
0.1.0 | 1,048 | 7/24/2017 |
- Added ARM and ARM64 support.