{"id":21954808,"url":"https://github.com/mgernand/expressionreflect","last_synced_at":"2025-04-23T12:07:07.240Z","repository":{"id":7289309,"uuid":"8604619","full_name":"mgernand/ExpressionReflect","owner":"mgernand","description":"Provides the ability to \"compile\" expressions to delegates without using Reflection.Emit but only using reflection.","archived":false,"fork":false,"pushed_at":"2024-03-19T14:16:55.000Z","size":3203,"stargazers_count":26,"open_issues_count":0,"forks_count":13,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-05-03T07:57:55.522Z","etag":null,"topics":["c-sharp","delegate","emit","execution","expression","reflection","runtime","xamarin","xamarin-ios"],"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/mgernand.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-03-06T14:06:21.000Z","updated_at":"2024-06-12T15:39:31.322Z","dependencies_parsed_at":"2024-06-12T15:39:30.389Z","dependency_job_id":"fa9e3706-b200-4a70-b7a7-38cb11881b14","html_url":"https://github.com/mgernand/ExpressionReflect","commit_stats":{"total_commits":96,"total_committers":4,"mean_commits":24.0,"dds":"0.26041666666666663","last_synced_commit":"8859ebde39dcb3ae80d29924a75ec39824ac01bb"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgernand%2FExpressionReflect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgernand%2FExpressionReflect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgernand%2FExpressionReflect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgernand%2FExpressionReflect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mgernand","download_url":"https://codeload.github.com/mgernand/ExpressionReflect/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227069531,"owners_count":17726231,"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":["c-sharp","delegate","emit","execution","expression","reflection","runtime","xamarin","xamarin-ios"],"created_at":"2024-11-29T07:26:11.087Z","updated_at":"2024-11-29T07:26:11.679Z","avatar_url":"https://github.com/mgernand.png","language":"C#","readme":"ExpressionReflect\n=================\n\nWhy?\n----\n\nProvides the ability to \"compile\" expressions to delegates without using Reflection.Emit but only using reflection.\nThe created delegate will make use of reflection to evaluate the expression when it is invoked. This is **very slow**\nwhen compared to executing a compiled delegate of an expression!\n\nThis framework is intended to be used where dynamic code creation is not possible. The main purpose is the usage with\nXamarin.iOS due to it's restriction on Reflection.Emit.\n\nHow?\n----\n\nThe expression tree is traversed and respective reflection calls are created and invoked. This is very slow compared \nto compiled expressions, so it should only be used with simple expressions.\n\nUsage\n-----\n\nThe usage is fairly simple. It's just an extension method on a expression.\n\n```csharp\nExpression\u003cFunc\u003cCustomer, string\u003e\u003e expression = x =\u003e x.Firstname;\nFunc\u003cCustomer, string\u003e reflection = expression.Reflect();\nstring result = reflection.Invoke(customer);\n```\n\nThe extension method `Reflect()` will return a delegate that will execute the reflection-based expression evaluation\ninternally.\n\nWhat is supported?\n------------------\n\nThe following built-in delegates are supported at the moment:\n\n* `Func\u003cT, TResult\u003e` (all variations)\n* `Action` und `Action\u003cT\u003e` (all variations)\n* `Predicate\u003cT\u003e`\n\nThe following expression types are supported at the moment:\n\n* Property getter\n```csharp\nx =\u003e x.Firstname\n```\n\n* Property getter with subsequent method call\n```csharp\nx =\u003e x.Firstname.ToLower();\n```\n\n* Method call with return value\n```csharp\nx =\u003e x.CalculateAge()\n```\n\n* Method call with return value and subsequent method call\n```csharp\nx =\u003e x.ToString().ToLower();\n```\n\n* Method call with return value and expression parameters\n```csharp\nx =\u003e x.CalculateLength(x.Firstname);\n```\n\n* Method call with return value, expression parameters and binary expression\n```csharp\nx =\u003e x.Calculate(x.Age + x.Value);\n```\n\n* Method call with return value, expression parameters, binary expression and constant\n```csharp\nx =\u003e x.Calculate(x.Age + 100);\n```\n\n* Method call with return value, expression parameters, binary expression and local variable\n```csharp\nint value = 666;\nx =\u003e x.Calculate(value);\n```\n\n* Method call with return value, expression parameters and nested constructor call.\n```csharp\nint value = 666;\nx =\u003e x.Calculate(new Customer(value));\n```\n\n* Method call with return value, expression parameters and nested method call.\n```csharp\nx.Calculate(x.CalculateAge());\n```\n\n* Method call with return value, expression parameters and local delegate call.\n```csharp\nFunc\u003cint\u003e method = () =\u003e 100;\nx =\u003e x.Calculate(method());\n```\n\n* Method call with return value, expression parameters and local delegate call with parameters.\n```csharp\nFunc\u003cint, int\u003e method = x =\u003e x + 100;\nx =\u003e x.Calculate(method(10));\n```\n\n* Method call with return value and mixed parameters\n```csharp\nx =\u003e x.CalculateLength(x.Firstname, x, 10);\n```\n\n* Constructor call\n```csharp\nx =\u003e new Customer();\n```\n\n* Constructor call with subsequent method call\n```csharp\nx =\u003e new Customer();\n```\n\n* Constructor call with expression parameters\n```csharp\nx =\u003e new Customer(x.Lastname, x.Firstname);\n```\n\n* Constructor call with expression parameters and binary expression\n```csharp\nx =\u003e new Customer(x.Age + x.Value);\n```\n\n* Constructor call with expression parameters, binary expression and constant\n```csharp\nx =\u003e new Customer(x.Age + 100);\n```\n\n* Constructor call with expression parameters, binary expression and local variable \n```csharp\nint value = 666;\nx =\u003e new Customer(value);\n```\n\n* Constructor call with expression parameters and nested costructor call\n```csharp\nint value = 666;\nx =\u003e new Customer(new Customer(value));\n```\n\n* Constructor call with expression parameters and nested method call.\n```csharp\nx =\u003e new Customer(x.CalculateAge());\n```\n\n* Constructor call with expression parameters and local delegate call.\n```csharp\nFunc\u003cint\u003e method = () =\u003e 100;\nx =\u003e new Customer(method());\n```\n\n* Constructor call with expression parameters and local delegate call with parameters.\n```csharp\nFunc\u003cint, int\u003e method = x =\u003e x + 100;\nx =\u003e new Customer(method(10));\n```\n\n* Constructor call with mixed parameters\n```csharp\nx =\u003e new Customer(x.Lastname, x, 10, x.Firstname);\n```\n\nSupported features\n------------------\n\n* `Func\u003cT, TResult\u003e`\n* `Action` und `Action\u003cT\u003e`\n* `Predicate\u003cT\u003e`\n* Property getters including indexers\n* Field access\n* Method calls with mixed parameters\n* Constructor invocations with mixed parameters\n* Local variables\n* Constant expressions\n* Local delegates\n* Local delegates with parameters (local and constant, binary expression)\n* Binary expressions including 'is' operator\n* Unary expressions (almost complete)\n* Array access\n* Array creation (simple arrays)\n* Object initializers (objects, lists, dictionaries)\n* Ternary conditionals\n* Nested expressions (f.e. LINQ extension methods: `x =\u003e x.FirstOrDefault(y.Name == \"John\")`)\n\nAll this features can be combined to more complex expressions.\n\nContributors\n------------\n\nBernhard Richter [seesharper](https://github.com/seesharper)\n\n\nThank you!","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgernand%2Fexpressionreflect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmgernand%2Fexpressionreflect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgernand%2Fexpressionreflect/lists"}