{"id":18339488,"url":"https://github.com/antelcat/il","last_synced_at":"2025-04-13T09:22:03.385Z","repository":{"id":171865028,"uuid":"648522930","full_name":"Antelcat/IL","owner":"Antelcat","description":"Extensions of ILGenerator and the ability to create delegates more easily","archived":false,"fork":false,"pushed_at":"2023-12-17T08:14:21.000Z","size":53,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2024-08-21T09:19:54.635Z","etag":null,"topics":["delegate","dotnet","emit","extension","il","ilgenerator","reflection"],"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/Antelcat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-06-02T07:05:29.000Z","updated_at":"2024-02-12T21:11:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"a4a73e5f-6dba-41a1-a02b-d98d93f3bf04","html_url":"https://github.com/Antelcat/IL","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"e8bc8b87244049a5291f6a9cd96250b83345bf6a"},"previous_names":["antelcat/ilgeneratorex","antelcat/il"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antelcat%2FIL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antelcat%2FIL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antelcat%2FIL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Antelcat%2FIL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Antelcat","download_url":"https://codeload.github.com/Antelcat/IL/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248689382,"owners_count":21145923,"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":["delegate","dotnet","emit","extension","il","ilgenerator","reflection"],"created_at":"2024-11-05T20:18:00.748Z","updated_at":"2025-04-13T09:22:03.363Z","avatar_url":"https://github.com/Antelcat.png","language":"C#","readme":"# Antelcat.IL\n\nExtensions of ILGenerator and the ability to create delegates more easily\n\n## Emit Extension\n\nAlong with [T4](https://learn.microsoft.com/zh-cn/visualstudio/modeling/code-generation-and-t4-text-templates?view=vs-2022) generated [ILExtension (Emit)](https://github.com/Antelcat/Antelcat.Shared/blob/main/src/Shared/IL/Extensions/ILExtension.g.cs), you can use Fluent Style EmitEx like :\n\n```c#\niLGenerator.EmitEx(OpCodes.Ldarg_0)\n                .EmitEx(OpCodes.Ldind_Ref)\n                .EmitEx(OpCodes.Unbox_Any, targetType)\n                .EmitEx(OpCodes.Stloc_0)\n                .EmitEx(OpCodes.Ldloca, 0)\n                ...\n```\n\n## Delegates\n\n### Supports\n\nYou can use extensions to create targets from these sources :\n\u003ctable\u003e\n\n\u003ctr\u003e\n    \u003cth\u003eSource\u003c/th\u003e\n    \u003cth\u003eTarget\u003c/th\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n    \u003ctd\u003eType\u003c/td\u003e\n    \u003ctd rowspan=2\u003eCtorHandler\u003c\u003e\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n    \u003ctd\u003eConstructorInfo\u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n    \u003ctd\u003e PropertyInfo \u003c/td\u003e\n    \u003ctd rowspan=2\u003e SetHandler\u003c,\u003e \u0026 GetHandler\u003c,\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\n\u003ctr\u003e\n    \u003ctd\u003eFieldInfo\u003c/td\u003e \n\u003c/tr\u003e\n\n\u003ctr\u003e\n    \u003ctd\u003e MethodInfo \u003c/td\u003e\n    \u003ctd rowspan=2\u003e InvokeHandler\u003c,\u003e \u003c/td\u003e\n\u003c/tr\u003e\n\n\u003c/table\u003e\n  \n### Usage\n\nCan be easily create delegate when you have a class like:\n\n``` c#\nclass Foo\n{\n    public Foo(int dependency){}\n    public int Method(ref int val) =\u003e ++val;\n    public static int StaticMethod(int val, out int source) \n    {\n        source = val--;\n        return val;\n    }\n    protected string Property { get; set; }\n    protected static string StaticProperty { get; set; }\n    private string field;\n    private static string staticField;\n}\n```\n\nThen :\n\n``` c#\nvar type = typeof(Foo);\n\nvar foo = type.GetConstructors()[0].CreateCtor().Invoke(1);\nobject? nothing = null;\n\ntype.GetMethod(nameof(Foo.Method)).CreateInvoker().Invoke(foo, 1);\ntype.GetMethod(nameof(Foo.StaticMethod)).CreateInvoker().Invoke(null, new object?[]{ 1, null });\n\nvar prop = type.GetProperty(nameof(Foo.Property));\nprop.CreateGetter().Invoke(foo);\nprop.CreateSetter().Invoke(ref foo, \"value\");\n\nvar staticProp = type.GetProperty(nameof(Foo.StaticProperty));\nstaticProp.CreateGetter().Invoke(null);\nstaticProp.CreateSetter().Invoke(ref nothing, \"value\");\n\nvar field = type.GetField(nameof(Foo.field));\nfield.CreateGetter().Invoke(foo);\nfield.CreateSetter().Invoke(ref foo, \"value\");\n\nvar staticField = type.GetField(nameof(Foo.staticField));\nstaticField.CreateGetter().Invoke(null);\nstaticField.CreateSetter().Invoke(ref nothing, \"value\");\n```\n\nTests can be found in [UnitTest.cs](./src/Antelcat.IL.Test/UnitTest.cs)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantelcat%2Fil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantelcat%2Fil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantelcat%2Fil/lists"}