{"id":19740716,"url":"https://github.com/hazzik/DelegateDecompiler","last_synced_at":"2025-04-30T05:33:36.054Z","repository":{"id":41258145,"uuid":"6292751","full_name":"hazzik/DelegateDecompiler","owner":"hazzik","description":"A library which is able to decompile a delegate or a method body to its lambda representation","archived":false,"fork":false,"pushed_at":"2024-08-19T08:15:58.000Z","size":2831,"stargazers_count":527,"open_issues_count":16,"forks_count":62,"subscribers_count":32,"default_branch":"main","last_synced_at":"2024-11-06T16:28:23.087Z","etag":null,"topics":["decompile","delegate","entity-framework","lambda-representation"],"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/hazzik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["hazzik"]}},"created_at":"2012-10-19T09:40:27.000Z","updated_at":"2024-11-04T09:09:13.000Z","dependencies_parsed_at":"2024-05-03T02:43:40.851Z","dependency_job_id":"401ca8e9-9278-4e64-a126-614a4fd84b15","html_url":"https://github.com/hazzik/DelegateDecompiler","commit_stats":{"total_commits":339,"total_committers":22,"mean_commits":"15.409090909090908","dds":"0.16224188790560468","last_synced_commit":"3e46812f4a78fea39d1806159d436e564fed55eb"},"previous_names":[],"tags_count":57,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazzik%2FDelegateDecompiler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazzik%2FDelegateDecompiler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazzik%2FDelegateDecompiler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hazzik%2FDelegateDecompiler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hazzik","download_url":"https://codeload.github.com/hazzik/DelegateDecompiler/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224091975,"owners_count":17254152,"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":["decompile","delegate","entity-framework","lambda-representation"],"created_at":"2024-11-12T01:23:00.850Z","updated_at":"2025-04-30T05:33:36.049Z","avatar_url":"https://github.com/hazzik.png","language":"C#","readme":"# DelegateDecompiler\n\n![https://ci.appveyor.com/project/hazzik/delegatedecompiler/branch/main](https://ci.appveyor.com/api/projects/status/github/hazzik/delegatedecompiler?branch=main\u0026svg=true)\n![https://nuget.org/packages/DelegateDecompiler](https://img.shields.io/nuget/dt/DelegateDecompiler.svg)\n\nA library that is able to decompile a delegate or a method body to their lambda representation\n\n## Sponsorship\n\nIf you like the library please consider [supporting my work](https://github.com/sponsors/hazzik).\n\n## Examples\n\n### Using computed properties in linq.\n\nAsume we have a class with a computed property\n\n```csharp\nclass Employee\n{\n    [Computed]\n    public string FullName =\u003e FirstName + \" \" + LastName;\n    public string LastName { get; set; }\n    public string FirstName { get; set; }\n}\n```\n\nAnd you are going to query employees by their full names\n\n```csharp\nvar employees = (from employee in db.Employees\n                 where employee.FullName == \"Test User\"\n                 select employee).Decompile().ToList();\n```\n\nWhen you call `.Decompile` method it decompiles your computed properties to their underlying representation and the query will become simmilar to the following query\n\n```csharp\nvar employees = (from employee in db.Employees\n                 where (employee.FirstName + \" \" + employee.LastName)  == \"Test User\"\n                 select employee).ToList();\n```\n\nIf your class doesn't have a [Computed] attribute, you can use the `.Computed()` extension method..\n\n```csharp\nvar employees = (from employee in db.Employees\n                 where employee.FullName.Computed() == \"Test User\"\n                 select employee).ToList();\n```\n\nAlso, you can call methods that return a single item (Any, Count, First, Single, etc) as well as other methods in identical way like this:\n\n```csharp\nbool exists = db.Employees.Decompile().Any(employee =\u003e employee.FullName == \"Test User\");\n```\n\nAgain, the `FullName` property will be decompiled:\n\n```csharp\nbool exists = db.Employees.Any(employee =\u003e (employee.FirstName + \" \" + employee.LastName) == \"Test User\");\n```\n\n## Limitations\n\nNot every compiled code can be represented as a lambda expression. Some cases are explicitly not supported, other can break and produce unexpected results.\n\nSome of the known cases listed below\n\n### Loops\n\nLoops often cannot be represented as an expression tree. \n\nSo, the following imperative code would probably throw a `StackOverflowException`:\n\n```csharp\nvar total = 0;\nforeach (var item in this.Items) { total += item.TotalPrice; }\nreturn total;\n```\n\nInstead, write it as a declarative Linq expression, which would be supported.\n\n```csharp\nreturn this.Items.Sum(i =\u003e i.TotalPrice);\n```\n\n### Recursion and self-referencing\n\nRecursion and self-referencing of computed properties cannot be represented as an Expression tree, \nand would probably throw `StackOverflowException` similarly to loops.\n\n## Using with EntityFramework and other ORMs\n\nIf you are using ORM specific features, like EF's `Include`, `AsNoTracking` or NH's `Fetch` then `Decompile` method should be called after all ORM specific methods, otherwise it may not work. Ideally use `Decompile` extension method just before materialization methods such as `ToList`, `ToArray`, `First`, `FirstOrDefault`, `Count`, `Any`, and etc.\n\n### Async Support with [EntityFramework 6](https://www.nuget.org/packages/DelegateDecompiler.EntityFramework)\n\nThe [DelegateDecompiler.EntityFramework](https://nuget.org/packages/DelegateDecompiler.EntityFramework) package provides `DecompileAsync` extension method which adds support for EF's Async operations.\n \n### Async Support with [EntityFramework Core 5.0 and later](https://www.nuget.org/packages/DelegateDecompiler.EntityFrameworkCore5)\n\nThe [DelegateDecompiler.EntityFrameworkCore5](https://nuget.org/packages/DelegateDecompiler.EntityFrameworkCore5) package provides `DecompileAsync` extension method which adds support for EF's Async operations.\n\n#### Automatic decompilation\n\nYou can configure DelegateDecompiler to automatically decompile all EF Core queries:\n\n```csharp\npublic class YourDbContext : DbContext\n{\n    protected override void OnConfiguring(DbContextOptionsBuilder options) {\n        options.AddDelegateDecompiler();\n        // Other configuration\n    }\n}\n```\n\nWith this approach you would not need to call `Decompile` or `DecompileAsync` methods on queries.\n \n# Installation\n\nAvailable on [NuGet](https://nuget.org/)\n\n* Install-Package [DelegateDecompiler](https://nuget.org/packages/DelegateDecompiler)\n* Install-Package [DelegateDecompiler.EntityFramework](https://nuget.org/packages/DelegateDecompiler.EntityFramework)\n* Install-Package [DelegateDecompiler.EntityFrameworkCore5](https://nuget.org/packages/DelegateDecompiler.EntityFrameworkCore5)\n\n# License\n\nMIT license - http://opensource.org/licenses/mit\n","funding_links":["https://github.com/sponsors/hazzik"],"categories":["Supported Packages"],"sub_categories":["Contents"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazzik%2FDelegateDecompiler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhazzik%2FDelegateDecompiler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhazzik%2FDelegateDecompiler/lists"}