{"id":16639385,"url":"https://github.com/bruce-dunwiddie/linq.expressions-examples","last_synced_at":"2026-03-09T18:03:20.299Z","repository":{"id":146940577,"uuid":"266461043","full_name":"bruce-dunwiddie/Linq.Expressions-Examples","owner":"bruce-dunwiddie","description":"Code examples of Linq.Expressions usage with explanations","archived":false,"fork":false,"pushed_at":"2020-05-31T07:43:47.000Z","size":29,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-18T12:19:59.172Z","etag":null,"topics":["expression","expression-tree","expressions","linq-expressions"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bruce-dunwiddie.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":"2020-05-24T03:14:59.000Z","updated_at":"2020-06-09T03:04:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"3c2ca65d-5ec5-4389-aba8-cf6d51d200a1","html_url":"https://github.com/bruce-dunwiddie/Linq.Expressions-Examples","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/bruce-dunwiddie%2FLinq.Expressions-Examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bruce-dunwiddie%2FLinq.Expressions-Examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bruce-dunwiddie%2FLinq.Expressions-Examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bruce-dunwiddie%2FLinq.Expressions-Examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bruce-dunwiddie","download_url":"https://codeload.github.com/bruce-dunwiddie/Linq.Expressions-Examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243147274,"owners_count":20243744,"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":["expression","expression-tree","expressions","linq-expressions"],"created_at":"2024-10-12T07:05:55.769Z","updated_at":"2026-03-09T18:03:15.266Z","avatar_url":"https://github.com/bruce-dunwiddie.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"Code examples of System.Linq.Expressions namespace class usage with explanations.\n\n### Topics\n\n- [Methods](Examples/Methods/README.md)\n\n- Constructors (Coming Soon)\n\n- Fields (Coming Soon)\n\n- [Properties](Examples/Properties/README.md)\n\n- Blocks (Coming Soon)\n\n- Variables (Coming Soon)\n\n- Constants (Coming Soon)\n\n- Casts (Coming Soon)\n\n- Loops (Coming Soon)\n\n- Conditions (Coming Soon)\n\nComplete unit tests with compilable project can also be found [here](https://github.com/bruce-dunwiddie/Linq.Expressions-Examples-Code).\n\n### Sample Code Example for Calling Instance Method\n\nThis example shows the general flow of creating the lambda delegate for\nexecuting an instance method. \n\n#### Fiddle: (https://dotnetfiddle.net/hFssOH)\n\n#### Code:\n\n```csharp\nDateTime testDate = DateTime.Parse(\"1/2/2020 1:23:45.678\");\n\n// locate the method to be called\nMethodInfo toString = testDate\n    .GetType()\n    .GetMethod(\n        \"ToString\",\n        new Type[] { typeof(string) });\n\n// ParameterExpression is used to map a value from the caller\n// to the lambda body\nParameterExpression date = Expression.Parameter(\n    testDate.GetType());\n\n// use Expression.Constant to convert a 'normal' value into an expression\nConstantExpression format = Expression.Constant(\n    \"hh:mm:ss\");\t\t\t\n\n// define the body of the lambda\n\n// we're going to just have a single method call within the body\nMethodCallExpression body = Expression.Call(\n    date,\n    toString,\n    new Expression[] { format });\n\n// Func\u003cin T, out TResult\u003e\n\n// first Type argument of Func definition will be Type of instance object\n// second Type argument of Func definition will be Type of return\n\nExpression\u003cFunc\u003cDateTime, string\u003e\u003e lambda = Expression.Lambda\u003cFunc\u003cDateTime, string\u003e\u003e(\n\n    // this is going to be the function body/logic\n    \n    // the value returned from a function is the last expression in its body\n    body,\n\n    // this is the parameter list being passed in to the lambda body\n\n    // have to use same ParameterExpression instances referenced in\n    // expression body definition above to get them to map through Func call\n    new ParameterExpression[] { date });\n\n// create the Func from the lambda\nFunc\u003cDateTime, string\u003e func = lambda.Compile();\n\n// can now use Func to execute instance method on object instance\n// and get result\nstring formattedDate = func(testDate);\n\nConsole.WriteLine(formattedDate);\n```\n\n#### Result:\n\n```\n01:23:45\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbruce-dunwiddie%2Flinq.expressions-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbruce-dunwiddie%2Flinq.expressions-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbruce-dunwiddie%2Flinq.expressions-examples/lists"}