https://github.com/sergio0694/privatelike
An attribute, generator and analyzer to declare "private-like" types in C# (internal but producing errors if not used as if they were declared as private)
https://github.com/sergio0694/privatelike
Last synced: 6 months ago
JSON representation
An attribute, generator and analyzer to declare "private-like" types in C# (internal but producing errors if not used as if they were declared as private)
- Host: GitHub
- URL: https://github.com/sergio0694/privatelike
- Owner: Sergio0694
- License: mit
- Created: 2023-12-17T19:36:18.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-17T22:17:43.000Z (almost 2 years ago)
- Last Synced: 2025-03-29T07:11:17.739Z (6 months ago)
- Language: C#
- Homepage:
- Size: 53.7 KB
- Stars: 10
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](https://github.com/Sergio0694/privatelike/actions) [](https://www.nuget.org/stats/packages/privatelike?groupby=Version) [](https://www.nuget.org/packages/privatelike/)
# What is it? 🚀
**privatelike** provides an attribute, generator and analyzer to declare "private-like" types in C# (internal but producing errors if not used as if they were declared as private). This can be used to still enforce the same acessibility as using the `private` keyword in scenarios where types actually still need to be accessible from elsewhere in the assembly. For instance, this is the case for some source generators (eg. the COM generators, or the ones from [ComputeSharp](https://github.com/Sergio0694/ComputeSharp)). Using the `[privatelike]` attribute can make things simpler in this scenario: the source generators can just suppress the errors, but the rest of the code will not, and should avoid referencing these types incorrectly.
# How to use it 📖
Simply declare a type as follows:
```csharp
[privatelike] partial struct MyPrivateLikeType
{
}
```The type will end up using `internal`, but referencing it from a place where it would've been an error if it had been using `private` will result in an error as well.