{"id":20688759,"url":"https://github.com/71/ryder","last_synced_at":"2025-04-22T15:42:38.266Z","repository":{"id":51225864,"uuid":"98201816","full_name":"71/Ryder","owner":"71","description":"Runtime redirection of method calls for .NET Core.","archived":false,"fork":false,"pushed_at":"2019-04-08T16:08:32.000Z","size":206,"stargazers_count":43,"open_issues_count":2,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-18T13:16:09.519Z","etag":null,"topics":["csharp","dotnet","dotnet-core","hook","intercept","redirect"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/71.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-24T14:47:32.000Z","updated_at":"2025-01-30T08:29:50.000Z","dependencies_parsed_at":"2022-09-07T17:51:35.928Z","dependency_job_id":null,"html_url":"https://github.com/71/Ryder","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2FRyder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2FRyder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2FRyder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/71%2FRyder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/71","download_url":"https://codeload.github.com/71/Ryder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250269954,"owners_count":21402970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","dotnet-core","hook","intercept","redirect"],"created_at":"2024-11-16T23:06:52.647Z","updated_at":"2025-04-22T15:42:38.242Z","avatar_url":"https://github.com/71.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003cimg src=\"./Ryder/Properties/Icon.png\" alt=\"Ryder\"\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  Ryder is a .NET Core library providing the ability to redirect method calls from one method to another. By extension, it can also redirect property accesses, and event subscriptions / raises.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://nuget.org/packages/Ryder\"\u003e\n    \u003cimg src=\"https://img.shields.io/nuget/v/Ryder.svg\" alt=\"NuGet\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"../../issues\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/issues-raw/6A/Ryder.svg\" alt=\"Issues\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"./LICENSE.md\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/6A/Ryder.svg\" alt=\"License\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n-----\n\n## Get started\n#### Redirect a method\n```csharp\npublic static int Incremented(int nbr) =\u003e nbr + 1;\npublic static int Decremented(int nbr) =\u003e nbr - 1;\n\nIncremented(1); // =\u003e 2.\n\nMethodRedirection r = Redirection.Redirect\u003cFunc\u003cint, int\u003e\u003e(Incremented, Decremented);\n\nIncremented(1); // =\u003e 0.\n\n// You can also invoke the original method:\nr.InvokeOriginal(null, 1); // =\u003e 2.\n\n// You can also stop the redirection...\nr.Stop(); // or r.IsRedirecting = false, or r.Dispose().\nIncremented(1); // =\u003e 2.\n\n// ... and restart it\nr.Start(); // or r.IsRedirecting = true, unless you disposed it, in which case it's no longer usable\nIncremented(1); // =\u003e 0.\n```\n\n#### Using Reactive Extensions\n```csharp\nMethodInfo method = typeof(DateTime)\n    .GetProperty(nameof(DateTime.Now), BindingFlags.Static | BindingFlags.Public)\n    .GetGetMethod();\n\nint count = 0;\nDateTime bday = new DateTime(1955, 10, 28);\n\n// Make \"DateTime.get_Now()\" return \"bday\" every two calls.\nusing (Redirection.Observe(method)\n                  .Where(_ =\u003e count++ % 2 == 0)\n                  .Subscribe(ctx =\u003e ctx.ReturnValue = bday))\n{\n    DateTime.Now.ShouldBe(bday);\n    DateTime.Now.ShouldNotBe(bday);\n    DateTime.Now.ShouldBe(bday);\n    DateTime.Now.ShouldNotBe(bday);\n}\n\nDateTime.Now.ShouldNotBe(bday);\nDateTime.Now.ShouldNotBe(bday);\n```\n\n#### Other features\n##### Any `Redirection` also defines the following members:\n- `bool IsRedirecting { get; set; }`\n- `void Start()`\n- `void Stop()`\n\n##### Redirections can be created in multiple ways:\n- `MethodRedirection`: `Redirect(Delegate, Delegate)`, `Redirect(MethodBase, MethodBase)`.\n- `PropertyRedirection`: `Redirect(PropertyInfo, PropertyInfo)`.\n- `EventRedirection`: `Redirect(EventInfo, EventInfo)`.\n\n##### Tests:\nAll features are tested in [Ryder.Tests](./Ryder.Tests). Please check it out, as it contains some real-world-usage code.\n\n##### Gloriously unsafe:\nBy 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`.\n\n##### Implicit JIT checks:\nWhen creating a `Redirection`, Ryder will ensure that the methods you use have already been jitted. If they haven't, they will be compiled automatically.\n\n##### Support for i386, x86_64, arm and arm64\nRyder is designed to work with `i386`, `x86_64`, `arm` and `arm64` using purely runtime checks. This means that it works everywhere\nwithout additional configuration. Additionally, Windows, Linux and OSX are all supported.\n\n## Installation\nYou can install Ryder through the NuGet package manager:\n```powershell\nInstall-Package Ryder\n```\n\nAlternatively, if you don't want to add a dependency, you can copy-paste the\n[`Ryder.Lightweight.cs`](./Ryder.Lightweight/Ryder.Lightweight.cs) file in your project. Caution, however, since this version only\nprovides the `MethodRedirection` class (simply called `Redirection`), and performs no safety checks.\n\n## Additional notes\n- 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.\n- 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 the `Redirection` is no longer guaranteed to work.\n\n## Inspiration\nRyder is highly inspired by [Harmony](https://github.com/pardeike/Harmony), but tries\nto 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.\n\n# Projects using Ryder\n- The [AnyConstraint](https://github.com/6A/AnyConstraint.Analyzer) analyzer uses [Ryder.Lightweight](./Ryder.Lightweight) to allow any constraint to be used, including `Delegate` and `Enum`.\n- [Cometary](https://github.com/6A/Cometary) highly modifies the [Roslyn](https://github.com/dotnet/roslyn) compilation process in order to add custom features to C#.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F71%2Fryder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F71%2Fryder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F71%2Fryder/lists"}