Description
- Support wildcards like
"System.Diagnostics.CodeAnalysis.*Null*Attribute" and "**.*Null*Attribute" in the <PolySharpIncludeGeneratedTypes> MSBuild property.
- Support type names without namespaces. I think it's safe to assume that there won't be name conflicts.
Rationale
Currently <PolySharpIncludeGeneratedTypes> property requires explicitly listing the full name of every type. If I want only attributes related to nullability analysis, I have to list 9 attributes, with namespaces and all. It would be nice to significantly simplify configuration with wildcards:
- Shorter: potentially just one short line instead of a huge block of copy-pasted namespaces.
- Easier: no need to remember full namespaces of every type.
Proposed API
<PolySharpIncludeGeneratedTypes>
**.*Null*Attribute; Range; Index; System.Runtime.Versioning.*
</PolySharpIncludeGeneratedTypes>
replaces:
<PolySharpIncludeGeneratedTypes>
System.Diagnostics.CodeAnalysis.AllowNullAttribute;
System.Diagnostics.CodeAnalysis.DisallowNullAttribute;
System.Diagnostics.CodeAnalysis.MaybeNullAttribute;
System.Diagnostics.CodeAnalysis.MaybeNullWhenAttribute;
System.Diagnostics.CodeAnalysis.MemberNotNullAttribute;
System.Diagnostics.CodeAnalysis.MemberNotNullWhenAttribute;
System.Diagnostics.CodeAnalysis.NotNullAttribute;
System.Diagnostics.CodeAnalysis.NotNullIfNotNullAttribute;
System.Diagnostics.CodeAnalysis.NotNullWhenAttribute;
System.Range;
System.Index;
System.Runtime.Versioning.RequiresPreviewFeaturesAttribute;
</PolySharpIncludeGeneratedTypes>
- strings without dots are prefixed with
**.
** turns into .+ regex
* turns into \w+ regex
- all regexes start with
^, end with $ and are case-insensitive
- all other characters are escaped
Drawbacks
- A bit more code in the library.
Alternatives
- Trickery with MSBuild transforms like:
<ItemGroup>
<PolySystem Include="Range;Index" />
<PolyAnalysisAttrs Include="AllowNull;DisallowNull;MaybeNull;MaybeNullWhen;MemberNotNull;MemberNotNullWhen;NotNull;NotNullIfNotNull;NotNullWhen" />
</ItemGroup>
<ItemGroup>
<PolyInclude Include="@(PolySystem->'System.%(Identity)')" />
<PolyInclude Include="@(PolyAnalysisAttrs->'System.Diagnostics.CodeAnalysis.%(Identity)Attribute')" />
</ItemGroup>
<Target Name="PolySharpIncludeTransform" BeforeTargets="ConfigurePolySharpMSBuildProperties">
<PropertyGroup>
<PolySharpIncludeGeneratedTypes>@(PolyInclude, ',');System.Runtime.Versioning.RequiresPreviewFeaturesAttribute</PolySharpIncludeGeneratedTypes>
</PropertyGroup>
</Target>
It's marginally shorter, but 10x harder to understand and more fragile.
Other thoughts
- Can implement myself if approved
Description
"System.Diagnostics.CodeAnalysis.*Null*Attribute"and"**.*Null*Attribute"in the<PolySharpIncludeGeneratedTypes>MSBuild property.Rationale
Currently
<PolySharpIncludeGeneratedTypes>property requires explicitly listing the full name of every type. If I want only attributes related to nullability analysis, I have to list 9 attributes, with namespaces and all. It would be nice to significantly simplify configuration with wildcards:Proposed API
replaces:
**.**turns into.+regex*turns into\w+regex^, end with$and are case-insensitiveDrawbacks
Alternatives
Other thoughts