{"id":26800602,"url":"https://github.com/ktsu-dev/strongstrings","last_synced_at":"2025-03-29T20:18:03.466Z","repository":{"id":166465672,"uuid":"641962096","full_name":"ktsu-dev/StrongStrings","owner":"ktsu-dev","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-04T14:46:54.000Z","size":268,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-29T10:22:10.830Z","etag":null,"topics":[],"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/ktsu-dev.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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-17T14:21:34.000Z","updated_at":"2024-10-04T14:46:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"c2c68a57-f4e8-43d6-afc2-47f0a2b632de","html_url":"https://github.com/ktsu-dev/StrongStrings","commit_stats":null,"previous_names":["ktsu-io/StrongStrings","ktsu-dev/strongstrings","ktsu-io/strongstrings"],"tags_count":60,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FStrongStrings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FStrongStrings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FStrongStrings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ktsu-dev%2FStrongStrings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ktsu-dev","download_url":"https://codeload.github.com/ktsu-dev/StrongStrings/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246237434,"owners_count":20745348,"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":[],"created_at":"2025-03-29T20:18:02.962Z","updated_at":"2025-03-29T20:18:03.458Z","avatar_url":"https://github.com/ktsu-dev.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# StrongStrings\n\nA library that provides a transparent wrapper around system strings and gives you strong typing, compile time feedback, and runtime validation.\n\nThe intention is to be able to provide usage context and validation to naked strings in a similar way that Enums do for integers.\n\n## Usage\n```csharp\nusing ktsu.StrongStrings;\n\n// Create a strong type by deriving a record class from StrongStringAbstract\u003cTDerived\u003e:\npublic record class MyStrongString : StrongStringAbstract\u003cMyStrongString\u003e { }\n\npublic class MyDemoClass\n{\n\tpublic MyStrongString Stronk { get; set; } = new();\n\n\tpublic static void Demo(MyStrongString inStrongString, string inSystemString, out MyStrongString outStrongString, out string outSystemString)\n\t{\n\t\t// You can implicitly cast down to a System.String\n\t\toutSystemString = inStrongString;\n\n\t\t// You must explicitly cast up to a StrongString\n\t\toutStrongString = (MyStrongString)inSystemString;\n\n\t\t//You can provide a StrongString to a method that expects a System.String\n\t\tPath.Combine(inStrongString, inSystemString);\n\n\t\t// You can use the .WeakString property or the .ToString() method to get the value of the underlying System.String\n\t\toutSystemString = inStrongString.WeakString;\n\t\toutSystemString = inStrongString.ToString();\n\n\t\t// You can not implicitly cast up to a StrongString\n\t\t// outStrongString = inSystemString; // This will not compile\n\n\t\t// You can not cast from one StrongString to another\n\t\t// OtherStrongString other = inStrongString; // This will not compile\n\t\t// OtherStrongString other = (OtherStrongString)inStrongString; // This will not compile either\n\t}\n}\n```\n\n## Validation\nYou can provide custom validators which will throw a `FormatException` at runtime to help you catch data errors.\n\nImplement the `ktsu.StrongStrings.IValidator` interface and provide it as a generic parameter when deriving your class:\n\n```csharp\npublic abstract class StartsWithHttp : IValidator\n{\n\tpublic static bool IsValid(AnyStrongString? strongString)\n\t{\n\t\tArgumentNullException.ThrowIfNull(strongString);\n\n\t\treturn strongString.StartsWith(\"http\", StringComparison.InvariantCultureIgnoreCase);\n\t}\n}\n\npublic abstract class EndsWithDotCom : IValidator\n{\n\tpublic static bool IsValid(AnyStrongString? strongString)\n\t{\n\t\tArgumentNullException.ThrowIfNull(strongString);\n\n\t\treturn strongString.EndsWith(\".com\", StringComparison.InvariantCultureIgnoreCase);\n\t}\n}\n\npublic record class MyValidatedString : StrongStringAbstract\u003cMyValidatedString, StartsWithHttp, EndsWithDotCom\u003e { }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsu-dev%2Fstrongstrings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fktsu-dev%2Fstrongstrings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fktsu-dev%2Fstrongstrings/lists"}