{"id":20996836,"url":"https://github.com/leandromoh/nullpropagationvisitor","last_synced_at":"2025-10-09T10:35:52.705Z","repository":{"id":51253557,"uuid":"367542378","full_name":"leandromoh/NullPropagationVisitor","owner":"leandromoh","description":"Expression visitor that applies null conditional member access the same way the C# null propagation operator (?.) does.","archived":false,"fork":false,"pushed_at":"2021-05-21T01:34:31.000Z","size":27,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-03T02:05:43.235Z","etag":null,"topics":["csharp","expression","expression-tree","null-safe","visitor"],"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/leandromoh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-15T04:53:04.000Z","updated_at":"2024-03-20T11:56:54.000Z","dependencies_parsed_at":"2022-09-08T22:30:26.106Z","dependency_job_id":null,"html_url":"https://github.com/leandromoh/NullPropagationVisitor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/leandromoh/NullPropagationVisitor","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandromoh%2FNullPropagationVisitor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandromoh%2FNullPropagationVisitor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandromoh%2FNullPropagationVisitor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandromoh%2FNullPropagationVisitor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leandromoh","download_url":"https://codeload.github.com/leandromoh/NullPropagationVisitor/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leandromoh%2FNullPropagationVisitor/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263245315,"owners_count":23436513,"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":["csharp","expression","expression-tree","null-safe","visitor"],"created_at":"2024-11-19T07:37:31.811Z","updated_at":"2025-10-09T10:35:47.667Z","avatar_url":"https://github.com/leandromoh.png","language":"C#","readme":"[![Nuget](https://img.shields.io/nuget/v/NullPropagationVisitor?style=plastic)](https://www.nuget.org/packages/NullPropagationVisitor/)\n[![Fuget](https://www.fuget.org/packages/NullPropagationVisitor/badge.svg)](https://www.fuget.org/packages/NullPropagationVisitor)\n![GitHub](https://img.shields.io/github/license/leandromoh/NullPropagationVisitor)\n\n# NullPropagationVisitor\n\n[Expression tree](https://docs.microsoft.com/dotnet/csharp/programming-guide/concepts/expression-trees/) is an amazing feature of C#, however it only supports a [limited subset of C# features](https://github.com/dotnet/csharplang/discussions/158).  \nWhile there is no native support to null propagation operator `a?.b`, this library can do the job as an [expression visitor](https://stackoverflow.com/questions/41432852/why-would-i-want-to-use-an-expressionvisitor).  \nJust call `Visit` method of the visitor and you are done!\n\nAs well the `?.` operator, the visitor evaluates its left-hand operand no more than once.  \nYou can use projects like [ReadableExpressions](https://github.com/agileobjects/ReadableExpressions) to check the expression returned by visitor.\n\n## Examples of use\n\nCheck some examples of use in [unit tests](NullPropagationVisitor.UnitTest/NullPropagationVisitorTest.cs)\n\n## Transformation\n\nIt works from the basic cenarios:\n\n```c#\nExpression\u003cFunc\u003cstring, int\u003e\u003e ex = str =\u003e str.Length;\n```\nwhich become something like\n```c#\n(string str) =\u003e\n{\n    string caller = str;\n\n    return (caller == null) ? null : (int?)caller.Length;\n}\n```\n\nTo the complex ones\n```c#\nExpression\u003cFunc\u003cstring, char\u003e\u003e ex = str =\u003e str == \"foo\" ? 'X' : Self(str).Length.ToString()[0];\n```\nwhich become something like\n```c#\n(string str) =\u003e (str == \"foo\")\n    ? (char?)'X'\n    : {\n        string caller =\n        {\n            int? caller =\n            {\n                string caller = Program.Self(str);\n\n                return (caller == null) ? null : (int?)caller.Length;\n            };\n\n            return (caller == null) ? null : ((int)caller).ToString();\n        };\n\n        return (caller == null) ? null : (char?)caller[0];\n    }\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleandromoh%2Fnullpropagationvisitor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleandromoh%2Fnullpropagationvisitor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleandromoh%2Fnullpropagationvisitor/lists"}