Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blowin/Blowin.Required
Implementation of proposal https://github.com/dotnet/csharplang/issues/3630
https://github.com/blowin/Blowin.Required
analyzer roslyn roslyn-analyzer
Last synced: 26 days ago
JSON representation
Implementation of proposal https://github.com/dotnet/csharplang/issues/3630
- Host: GitHub
- URL: https://github.com/blowin/Blowin.Required
- Owner: blowin
- Created: 2021-10-07T04:49:36.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-17T14:19:09.000Z (about 3 years ago)
- Last Synced: 2024-05-18T22:33:51.927Z (7 months ago)
- Topics: analyzer, roslyn, roslyn-analyzer
- Language: C#
- Homepage:
- Size: 449 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-analyzers - Blowin.Required - Implementation of proposal 'Required Properties' https://github.com/dotnet/csharplang/issues/3630. (Popular Analyzers / Analyzer collections)
README
# Blowin.Required
![Build](https://github.com/blowin/Blowin.Required/actions/workflows/dotnet.yml/badge.svg)
| Source | Link |
| ----------- | ----------- |
| VSIX | [![VSIX](https://img.shields.io/visual-studio-marketplace/v/Blowin.requiredproperty)](https://marketplace.visualstudio.com/items?itemName=Blowin.requiredproperty) |
| Nuget | [![NUGET package](https://img.shields.io/nuget/v/Blowin.Required.svg)](https://www.nuget.org/packages/Blowin.Required/) |Implementation of proposal 'Required Properties'
https://github.com/dotnet/csharplang/issues/3630Add required attribute to property and enjoy :)
```c#
public class Person
{
public string Name { get; set; }
[Required]
public int Age { get; set; }
}
```You can use DataAnnotation, or any attribute with name Required
Support diagnostics:
1. Required property must be initialized (initializer)
2. Type can't be used as generic parameter with new() restriction
3. If constructor initialization of required property, it should be initialized in any execution path### Success cases:
![initializer](https://github.com/blowin/Blowin.Required/blob/master/images/initializer_ok.jpg)
![initializer from constructor non required](https://github.com/blowin/Blowin.Required/blob/master/images/ctor_ok.PNG)
![constructor & initializer](https://github.com/blowin/Blowin.Required/blob/master/images/ctor_initializer_ok.PNG)
![initializer from constructor required](https://github.com/blowin/Blowin.Required/blob/master/images/ctor_required_initialization_ok.PNG)### Fail cases:
![Initializer](https://github.com/blowin/Blowin.Required/blob/master/images/initializer.jpg)
![Ctor fail](https://github.com/blowin/Blowin.Required/blob/master/images/ctor_fail.jpg)
![Initialization required property from ctor](https://github.com/blowin/Blowin.Required/blob/master/images/ctor_required_initialization_fail.jpg)
![Generic class restriction](https://github.com/blowin/Blowin.Required/blob/master/images/generic_class_generic_restriction_fail.jpg)
![Generic method restriction](https://github.com/blowin/Blowin.Required/blob/master/images/generic_method_generic_restriction_fail.jpg)
![Generic method, restriction for implicit parameter](https://github.com/blowin/Blowin.Required/blob/master/images/generic_method_implicit_parameter_generic_restriction_fail.jpg)