{"id":22206730,"url":"https://github.com/usercode/smartresults","last_synced_at":"2025-04-07T00:24:19.674Z","repository":{"id":237559386,"uuid":"794742925","full_name":"usercode/SmartResults","owner":"usercode","description":"Lightweight .NET library to use result pattern instead of throwing exceptions.","archived":false,"fork":false,"pushed_at":"2024-06-11T21:44:32.000Z","size":65,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-07T07:53:09.658Z","etag":null,"topics":["csharp","pattern","results"],"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/usercode.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":"2024-05-01T21:23:25.000Z","updated_at":"2024-07-21T20:44:56.000Z","dependencies_parsed_at":"2024-05-04T01:24:29.445Z","dependency_job_id":"60cfcf86-906f-47ee-abe3-355e08fd8d8f","html_url":"https://github.com/usercode/SmartResults","commit_stats":null,"previous_names":["usercode/smartresults"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercode%2FSmartResults","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercode%2FSmartResults/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercode%2FSmartResults/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/usercode%2FSmartResults/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/usercode","download_url":"https://codeload.github.com/usercode/SmartResults/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227777711,"owners_count":17818455,"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","pattern","results"],"created_at":"2024-12-02T18:17:43.558Z","updated_at":"2024-12-02T18:17:44.197Z","avatar_url":"https://github.com/usercode.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SmartResults\nLightweight .NET library to use result pattern instead of throwing exceptions.\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![NuGet](https://img.shields.io/nuget/vpre/SmartResults.svg)](https://www.nuget.org/packages/SmartResults/)\n\n## How to use it\n- `Result` and `Result\u003cT\u003e` are structs to prevent memory allocation\n- Support for JSON\n  - Integrated JsonConverter for `Result` and `Result\u003cT\u003e`\n  - Polymorphic `Error` objects\n- Extensions for HttpResponseMessage\n- Chaining flow\n- Exception flow\n\n### Create and use results\n```csharp\nResult result = Result.Ok();\n\nif (result.IsSucceeded)\n{\n   Console.WriteLine(\"Succeeded\");\n}\nelse\n{\n   Console.WriteLine(result.Error);\n}\n```\n\n### Create and use results with value\n```csharp\nResult\u003cint\u003e result = Result.Ok(100);\n\nif (result.IsSucceeded)\n{\n   Console.WriteLine(result.Value);\n}\nelse\n{\n   Console.WriteLine(result.Error);\n}\n```\n\n### Create and use failed results\n```csharp\nResult\u003cint\u003e result = Result.Failed(\"Something is wrong!\");\nResult\u003cint\u003e result = Result.Failed(new Error(..));\n\nif (result.IsFailed)\n{\n   Console.WriteLine(result.Error);\n}\n\n```\n\n### Use match to evaluate the result\n```csharp\nResult\u003cint\u003e result = Result.Ok(100);\n\nbool b = result.Match(value =\u003e true, error =\u003e false);\n```\n### Explicit conversion\n\n```csharp\nResult\u003cstring\u003e result = Result.Ok(100).ToResult\u003cstring\u003e(x =\u003e x.ToString());\n```\n\n### Implicit operator for value\n\n```csharp\nResult\u003cint\u003e result = 100;\n\nint value = result;\n```\n\n### Exception flow by implicit operator\n```csharp\nint value = Create(); //throws exception if result is failed\n```\n\n### Chaining flow\n\n```csharp\nResult result1 = Create().Then(x =\u003e Console.WriteLine(x));\n\nResult result2 = await Create().ThenAsync(async x =\u003e await Service.ExecuteAsync(x));\n\nResult result3 = await CreateAsync().ThenAsync(x =\u003e Console.WriteLine(x));\n\nResult result4 = await CreateAsync().ThenAsync(async x =\u003e await Service.ExecuteAsync(x));\n```\n\n### HttpClient extensions\n\n```csharp\nResult result1 = await httpClient.GetAsync(\"/\").ReadResultFromJsonAsync();\n\nResult\u003cint\u003e result2 = await httpClient.GetAsync(\"/\").ReadResultFromJsonAsync\u003cint\u003e();\n```\n\n### Supports polymorphic error objects for JSON\n\n```csharp\npublic class PermissionError : IError { }\n\nError.Register\u003cPermissionError\u003e();\n\nResult result = Result.Failed(new PermissionError(\"Error\"));\n\nstring json = JsonSerializer.Serialize(result);\n\nResult result2 = JsonSerializer.Deserialize\u003cResult\u003e(json);\n\nresult2.Error //PermissionError\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusercode%2Fsmartresults","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fusercode%2Fsmartresults","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fusercode%2Fsmartresults/lists"}