{"id":15647292,"url":"https://github.com/xljiulang/predicatelib","last_synced_at":"2025-04-30T12:41:09.252Z","repository":{"id":40614107,"uuid":"177945481","full_name":"xljiulang/PredicateLib","owner":"xljiulang","description":"谓词筛选表达式Expression\u003cFunc\u003cT, bool\u003e\u003e的扩展库","archived":false,"fork":false,"pushed_at":"2019-04-05T19:18:06.000Z","size":87,"stargazers_count":44,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"x","last_synced_at":"2025-04-12T22:05:01.259Z","etag":null,"topics":["expression","expression-tree"],"latest_commit_sha":null,"homepage":null,"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/xljiulang.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}},"created_at":"2019-03-27T07:55:55.000Z","updated_at":"2024-11-22T10:51:34.000Z","dependencies_parsed_at":"2022-09-21T22:31:24.904Z","dependency_job_id":null,"html_url":"https://github.com/xljiulang/PredicateLib","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/xljiulang%2FPredicateLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xljiulang%2FPredicateLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xljiulang%2FPredicateLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xljiulang%2FPredicateLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xljiulang","download_url":"https://codeload.github.com/xljiulang/PredicateLib/tar.gz/refs/heads/x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251701963,"owners_count":21629925,"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"],"created_at":"2024-10-03T12:18:14.062Z","updated_at":"2025-04-30T12:41:09.231Z","avatar_url":"https://github.com/xljiulang.png","language":"C#","readme":"# PredicateLib\n[PredicateLib](https://github.com/xljiulang/PredicateLib)是谓词筛选表达式Expression\u0026lt;Func\u0026lt;T, bool\u003e\u003e的一个扩展库，它可以帮你创建一个复杂且灵活的Expression\u0026lt;Func\u0026lt;T, bool\u003e\u003e，以作为EF、MongoDB Driver等ORM框架的查询条件。\n\n\u003e nuget\n\n`PM\u003e install-package PredicateLib`\n\n### 1 Predicate的创建\n#### 1.1 true或false Predicate\n```c#\nvar predicate = Predicate.True\u003cUser\u003e();\n```\n\u003e 表达式输出\n\n```c#\nitem =\u003e true\n```\n\n#### 1.2 通过属性创建Predicate\n```c#\nvar predicate = Predicate.Create\u003cUser\u003e(\"age\", 2, Operator.GreaterThan);\n```\n\n\u003e 表达式输出\n\n```c#\nitem =\u003e (item.Age \u003e 2)\n```\n\n\n### 2 Predicate的逻辑扩展\n```c#\nvar predicate = Predicate\n    .True\u003cUser\u003e()\n    .And(item =\u003e item.Name == \"laojiu\");\n\nif (true)\n{\n    predicate = predicate.And(item =\u003e item.Age \u003e 10 \u0026\u0026 item.Age \u003c 20);\n}\n```\n\u003e 表达式输出\n\n```c#\nitem =\u003e ((True AndAlso (item.Name == \"laojiu\")) AndAlso ((item.Age \u003e 10) AndAlso (item.Age \u003c 20)))\n```\n\n\n### 3 Condition转换为Predicate\nCondition对象支持传入`IEnumerable\u003cKeyValuePair\u003c,\u003e\u003e`，`IEnumerable\u003cConditionItem\u003e`等类型作为条件项，然后转换为Predicate，适用于前端传入查询不确定的字段与值，后端不需要修改代码的需求。\n\n```c#\nvar uri = new Uri(\"http://www.xx.com/?age=1\u0026name=laojiu\u0026id=001\");\n\nvar condition = uri.AsCondition\u003cUser\u003e()\n    .OperatorFor(item =\u003e item.Age, Operator.GreaterThan)\n    .IgnoreFor(item =\u003e item.Id);\n\nvar predicate = condition.ToAndPredicate();\n```\n\u003e 表达式输出\n\n```c#\nitem =\u003e ((item.Age \u003e 1) AndAlso item.Name.Contains(\"laojiu\".Value))\n```\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxljiulang%2Fpredicatelib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxljiulang%2Fpredicatelib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxljiulang%2Fpredicatelib/lists"}