Skip to content

Commit dc13ec9

Browse files
feat: update charpier and reformat
1 parent 4c288d0 commit dc13ec9

10 files changed

Lines changed: 131 additions & 134 deletions

File tree

.config/dotnet-tools.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"isRoot": true,
44
"tools": {
55
"csharpier": {
6-
"version": "0.28.2",
6+
"version": "1.1.2",
77
"commands": [
8-
"dotnet-csharpier"
8+
"csharpier"
99
],
1010
"rollForward": false
1111
}
Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<IsRoslynComponent>true</IsRoslynComponent>
6-
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
7-
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
8-
<Configurations>Debug;Release;DebugGenerator</Configurations>
9-
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
10-
<DevelopmentDependency>true</DevelopmentDependency>
11-
<IncludeBuildOutput>false</IncludeBuildOutput>
12-
<LangVersion>latest</LangVersion>
13-
<Nullable>enable</Nullable>
14-
<SourceGenerator_EnableLogging>True</SourceGenerator_EnableLogging>
15-
<SourceGenerator_EnableDebug>False</SourceGenerator_EnableDebug>
16-
<SourceGenerator_DetailedLog>True</SourceGenerator_DetailedLog>
17-
<SourceGenerator_IntellisenseFix>True</SourceGenerator_IntellisenseFix>
18-
<Company>codecentric</Company>
19-
<Copyright>(c) codecentric</Copyright>
20-
<PackageProjectUrl>https://github.com/codecentric/net_automatic_interface</PackageProjectUrl>
21-
<Description>Source Generator to create an Interface from a class definition</Description>
22-
<RepositoryUrl>https://github.com/codecentric/net_automatic_interface.git</RepositoryUrl>
23-
<RepositoryType>git</RepositoryType>
24-
<PackageTags>interface; class; Source Generator</PackageTags>
25-
<PackageLicenseExpression>MIT</PackageLicenseExpression>
26-
<EnableNETAnalyzers>True</EnableNETAnalyzers>
27-
<AnalysisLevel>latest-Recommended</AnalysisLevel>
28-
<Version>5.2.0</Version>
29-
<PackageReadmeFile>README.md</PackageReadmeFile>
30-
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
31-
<NoWarn>1701;1702;NU5128</NoWarn>
32-
<PackageReleaseNotes>mproves inheritdoc so that developer documentation is properly referenced on the autogenerated interfaces</PackageReleaseNotes>
33-
</PropertyGroup>
34-
35-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugGenerator|AnyCPU'">
36-
<DefineConstants>TRACE;DEBUGGENERATOR</DefineConstants>
37-
38-
</PropertyGroup>
39-
40-
<ItemGroup>
41-
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
42-
<PrivateAssets>all</PrivateAssets>
43-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
44-
</PackageReference>
45-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" PrivateAssets="all" />
46-
</ItemGroup>
47-
48-
<ItemGroup>
49-
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
50-
<None Include="../../README.md" Pack="true" PackagePath="\" />
51-
</ItemGroup>
2+
<PropertyGroup>
3+
<TargetFramework>netstandard2.0</TargetFramework>
4+
<IsRoslynComponent>true</IsRoslynComponent>
5+
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
6+
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
7+
<Configurations>Debug;Release;DebugGenerator</Configurations>
8+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
9+
<DevelopmentDependency>true</DevelopmentDependency>
10+
<IncludeBuildOutput>false</IncludeBuildOutput>
11+
<LangVersion>latest</LangVersion>
12+
<Nullable>enable</Nullable>
13+
<SourceGenerator_EnableLogging>True</SourceGenerator_EnableLogging>
14+
<SourceGenerator_EnableDebug>False</SourceGenerator_EnableDebug>
15+
<SourceGenerator_DetailedLog>True</SourceGenerator_DetailedLog>
16+
<SourceGenerator_IntellisenseFix>True</SourceGenerator_IntellisenseFix>
17+
<Company>codecentric</Company>
18+
<Copyright>(c) codecentric</Copyright>
19+
<PackageProjectUrl>https://github.com/codecentric/net_automatic_interface</PackageProjectUrl>
20+
<Description>Source Generator to create an Interface from a class definition</Description>
21+
<RepositoryUrl>https://github.com/codecentric/net_automatic_interface.git</RepositoryUrl>
22+
<RepositoryType>git</RepositoryType>
23+
<PackageTags>interface; class; Source Generator</PackageTags>
24+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
25+
<EnableNETAnalyzers>True</EnableNETAnalyzers>
26+
<AnalysisLevel>latest-Recommended</AnalysisLevel>
27+
<Version>5.2.0</Version>
28+
<PackageReadmeFile>README.md</PackageReadmeFile>
29+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
30+
<NoWarn>1701;1702;NU5128</NoWarn>
31+
<PackageReleaseNotes>mproves inheritdoc so that developer documentation is properly referenced on the autogenerated interfaces</PackageReleaseNotes>
32+
</PropertyGroup>
33+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugGenerator|AnyCPU'">
34+
<DefineConstants>TRACE;DEBUGGENERATOR</DefineConstants>
35+
</PropertyGroup>
36+
<ItemGroup>
37+
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.3">
38+
<PrivateAssets>all</PrivateAssets>
39+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
40+
</PackageReference>
41+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.5.0" PrivateAssets="all" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<None
45+
Include="$(OutputPath)\$(AssemblyName).dll"
46+
Pack="true"
47+
PackagePath="analyzers/dotnet/cs"
48+
Visible="false"
49+
/>
50+
<None Include="../../README.md" Pack="true" PackagePath="\" />
51+
</ItemGroup>
5252
</Project>

AutomaticInterface/AutomaticInterface/Builder.cs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,33 @@ public static class Builder
1212
private static string InheritDoc(ISymbol source) =>
1313
$"/// <inheritdoc cref=\"{source.ToDisplayString().Replace('<', '{').Replace('>', '}')}\" />"; // we use inherit doc because that should be able to fetch documentation from base classes.
1414

15-
private static readonly SymbolDisplayFormat FullyQualifiedDisplayFormat =
16-
new(
17-
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
18-
memberOptions: SymbolDisplayMemberOptions.IncludeParameters
19-
| SymbolDisplayMemberOptions.IncludeContainingType,
20-
parameterOptions: SymbolDisplayParameterOptions.IncludeType
21-
| SymbolDisplayParameterOptions.IncludeParamsRefOut
22-
| SymbolDisplayParameterOptions.IncludeDefaultValue
23-
| SymbolDisplayParameterOptions.IncludeName,
24-
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
25-
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included,
26-
miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes
27-
| SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier
28-
| SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers
29-
);
15+
private static readonly SymbolDisplayFormat FullyQualifiedDisplayFormat = new(
16+
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
17+
memberOptions: SymbolDisplayMemberOptions.IncludeParameters
18+
| SymbolDisplayMemberOptions.IncludeContainingType,
19+
parameterOptions: SymbolDisplayParameterOptions.IncludeType
20+
| SymbolDisplayParameterOptions.IncludeParamsRefOut
21+
| SymbolDisplayParameterOptions.IncludeDefaultValue
22+
| SymbolDisplayParameterOptions.IncludeName,
23+
typeQualificationStyle: SymbolDisplayTypeQualificationStyle.NameAndContainingTypesAndNamespaces,
24+
globalNamespaceStyle: SymbolDisplayGlobalNamespaceStyle.Included,
25+
miscellaneousOptions: SymbolDisplayMiscellaneousOptions.UseSpecialTypes
26+
| SymbolDisplayMiscellaneousOptions.IncludeNullableReferenceTypeModifier
27+
| SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers
28+
);
3029

3130
/// <summary>
3231
/// We do need to be able to group shadowing and new methods/events into a single entry, hence this is missing SymbolDisplayMemberOptions.IncludeContainingType
3332
/// </summary>
34-
private static readonly SymbolDisplayFormat FullyQualifiedDisplayFormatForGrouping =
35-
new(
36-
genericsOptions: FullyQualifiedDisplayFormat.GenericsOptions,
37-
memberOptions: FullyQualifiedDisplayFormat.MemberOptions
38-
& ~SymbolDisplayMemberOptions.IncludeContainingType,
39-
parameterOptions: FullyQualifiedDisplayFormat.ParameterOptions,
40-
typeQualificationStyle: FullyQualifiedDisplayFormat.TypeQualificationStyle,
41-
globalNamespaceStyle: FullyQualifiedDisplayFormat.GlobalNamespaceStyle,
42-
miscellaneousOptions: FullyQualifiedDisplayFormat.MiscellaneousOptions
43-
);
33+
private static readonly SymbolDisplayFormat FullyQualifiedDisplayFormatForGrouping = new(
34+
genericsOptions: FullyQualifiedDisplayFormat.GenericsOptions,
35+
memberOptions: FullyQualifiedDisplayFormat.MemberOptions
36+
& ~SymbolDisplayMemberOptions.IncludeContainingType,
37+
parameterOptions: FullyQualifiedDisplayFormat.ParameterOptions,
38+
typeQualificationStyle: FullyQualifiedDisplayFormat.TypeQualificationStyle,
39+
globalNamespaceStyle: FullyQualifiedDisplayFormat.GlobalNamespaceStyle,
40+
miscellaneousOptions: FullyQualifiedDisplayFormat.MiscellaneousOptions
41+
);
4442

4543
public static string BuildInterfaceFor(ITypeSymbol typeSymbol)
4644
{
@@ -288,12 +286,11 @@ private static PropertySetKind GetSetKind(IMethodSymbol? setMethodSymbol)
288286
return setMethodSymbol switch
289287
{
290288
null => PropertySetKind.NoSet,
291-
{ IsInitOnly: true, DeclaredAccessibility: Accessibility.Public }
292-
=> PropertySetKind.Init,
293-
_
294-
=> setMethodSymbol is { DeclaredAccessibility: Accessibility.Public }
295-
? PropertySetKind.Always
296-
: PropertySetKind.NoSet,
289+
{ IsInitOnly: true, DeclaredAccessibility: Accessibility.Public } =>
290+
PropertySetKind.Init,
291+
_ => setMethodSymbol is { DeclaredAccessibility: Accessibility.Public }
292+
? PropertySetKind.Always
293+
: PropertySetKind.NoSet,
297294
};
298295
}
299296

AutomaticInterface/AutomaticInterface/InterfaceBuilder.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,9 @@ public string Build()
104104
cb.AppendLine(
105105
"[global::System.CodeDom.Compiler.GeneratedCode(\"AutomaticInterface\", \"\")]"
106106
);
107-
cb.AppendLine($"{(asInternal ? "internal" : "public")} partial interface {interfaceName}{genericType}");
107+
cb.AppendLine(
108+
$"{(asInternal ? "internal" : "public")} partial interface {interfaceName}{genericType}"
109+
);
108110
cb.AppendLine("{");
109111

110112
cb.Indent();
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
6-
<Nullable>enable</Nullable>
7-
<Configurations>Debug;Release;DebugGenerator</Configurations>
8-
<SourceGenerator_EnableLogging>True</SourceGenerator_EnableLogging>
9-
<SourceGenerator_EnableDebug>True</SourceGenerator_EnableDebug>
10-
<SourceGenerator_DetailedLog>True</SourceGenerator_DetailedLog>
11-
<SourceGenerator_IntellisenseFix>True</SourceGenerator_IntellisenseFix>
12-
</PropertyGroup>
13-
14-
<ItemGroup>
15-
<ProjectReference Include="..\AutomaticInterface\AutomaticInterface.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
16-
</ItemGroup>
17-
18-
<ItemGroup>
19-
<Folder Include="logs" />
20-
</ItemGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<Configurations>Debug;Release;DebugGenerator</Configurations>
7+
<SourceGenerator_EnableLogging>True</SourceGenerator_EnableLogging>
8+
<SourceGenerator_EnableDebug>True</SourceGenerator_EnableDebug>
9+
<SourceGenerator_DetailedLog>True</SourceGenerator_DetailedLog>
10+
<SourceGenerator_IntellisenseFix>True</SourceGenerator_IntellisenseFix>
11+
</PropertyGroup>
12+
<ItemGroup>
13+
<ProjectReference
14+
Include="..\AutomaticInterface\AutomaticInterface.csproj"
15+
OutputItemType="Analyzer"
16+
ReferenceOutputAssembly="false"
17+
/>
18+
</ItemGroup>
19+
<ItemGroup>
20+
<Folder Include="logs" />
21+
</ItemGroup>
2122
</Project>
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<Project>
22
<!-- Include each file with given extension from None collection to EmbeddedResource-->
33
<ItemGroup>
4-
<EmbeddedResource Include="@(None -> WithMetadataValue('Extension', '.scriban'))" />
5-
<EmbeddedResource Include="@(None -> WithMetadataValue('Extension', '.cstemplate'))" />
4+
<EmbeddedResource Include="@(None -&gt; WithMetadataValue('Extension', '.scriban'))" />
5+
<EmbeddedResource Include="@(None -&gt; WithMetadataValue('Extension', '.cstemplate'))" />
66
</ItemGroup>
7-
87
<!-- Set visibility of those props to SourceGenerator-->
98
<ItemGroup>
109
<CompilerVisibleProperty Include="SourceGenerator_EnableLogging" />
@@ -14,40 +13,42 @@
1413
<CompilerVisibleProperty Include="IntermediateOutputPath" />
1514
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="Type" />
1615
</ItemGroup>
17-
1816
<!-- Fix for IDE to make intellisense working-->
1917
<!--<ItemGroup Condition="'$(SourceGenerator_IntellisenseFix)' == 'true'">
2018
<Compile Include="$(IntermediateOutputPath)*.generated.cs"
2119
Condition="'$(DesignTimeBuild)' == 'true'"
2220
Link="%(Filename)%(Extension)"
2321
Visible="false" />
2422
</ItemGroup>-->
25-
2623
<!-- Include each nuget reference with property 'LocalSourceGenerators' into final-->
27-
<Target Name="AddLocalDependencies"
28-
Inputs="@(RuntimeCopyLocalItems)"
29-
Outputs="%(RuntimeCopyLocalItems.NuGetPackageId)"
30-
AfterTargets="ResolvePackageAssets">
24+
<Target
25+
Name="AddLocalDependencies"
26+
Inputs="@(RuntimeCopyLocalItems)"
27+
Outputs="%(RuntimeCopyLocalItems.NuGetPackageId)"
28+
AfterTargets="ResolvePackageAssets"
29+
>
3130
<!-- Get NuGetPackageId from RuntimeCopyLocalItems-->
3231
<ItemGroup>
33-
<NuGetPackageId Include="@(RuntimeCopyLocalItems -> '%(NuGetPackageId)')" />
32+
<NuGetPackageId Include="@(RuntimeCopyLocalItems -&gt; '%(NuGetPackageId)')" />
3433
</ItemGroup>
3534
<!-- Distinc results -->
3635
<PropertyGroup>
3736
<NuGetPackageId>@(NuGetPackageId -&gt; Distinct())</NuGetPackageId>
3837
</PropertyGroup>
3938
<!-- Get all PackageReference matching names from NuGetPackageId -->
4039
<ItemGroup>
41-
<PackageReferenceDependency
42-
Include="@(PackageReference -&gt; WithMetadataValue('Identity', '$(NuGetPackageId)'))" />
40+
<PackageReferenceDependency Include="@(PackageReference -&gt; WithMetadataValue('Identity', '$(NuGetPackageId)'))" />
4341
</ItemGroup>
4442
<!-- Get metadata 'LocalSourceGenerators' from PackageReference-->
4543
<PropertyGroup>
46-
<NuGetPackageLocalSourceGen>@(PackageReferenceDependency -> '%(LocalSourceGenerators)')</NuGetPackageLocalSourceGen>
44+
<NuGetPackageLocalSourceGen>@(PackageReferenceDependency -&gt; '%(LocalSourceGenerators)')</NuGetPackageLocalSourceGen>
4745
</PropertyGroup>
4846
<!-- For packages with attribute LocalSourceGenerators add library to final solution-->
4947
<ItemGroup Condition="'$(NuGetPackageLocalSourceGen)' == 'true'">
50-
<TargetPathWithTargetPlatformMoniker Include="@(RuntimeCopyLocalItems)" IncludeRuntimeDependency="false" />
48+
<TargetPathWithTargetPlatformMoniker
49+
Include="@(RuntimeCopyLocalItems)"
50+
IncludeRuntimeDependency="false"
51+
/>
5152
</ItemGroup>
5253
</Target>
53-
</Project>
54+
</Project>
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
43
<OutputType>Exe</OutputType>
54
<TargetFramework>net8.0</TargetFramework>
65
</PropertyGroup>
7-
86
<ItemGroup>
97
<PackageReference Include="AutomaticInterface" Version="4.1.0">
108
<PrivateAssets>all</PrivateAssets>
119
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1210
</PackageReference>
1311
</ItemGroup>
14-
1512
</Project>

AutomaticInterface/Tests/Enums/Enums.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class DemoClass
2222
{
2323
public void MethodWithDefaultParameter(EnumWithByteType a = EnumWithByteType.B) { }
2424
}
25-
25+
2626
""";
2727

2828
await Verify(Infrastructure.GenerateCode(code))

AutomaticInterface/Tests/Misc/Misc.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,8 @@ class DemoClass
366366
}
367367

368368
[Fact]
369-
public async Task AsInternal()
370-
{
369+
public async Task AsInternal()
370+
{
371371
const string code = """
372372
373373
using AutomaticInterface;
@@ -381,13 +381,13 @@ public string AMethod(DemoClass? x, string y)
381381
}
382382
}
383383
384-
""";
384+
""";
385385
await Verify(Infrastructure.GenerateCode(code));
386-
}
387-
386+
}
387+
388388
[Fact]
389-
public async Task AsInternalExplicitFalse()
390-
{
389+
public async Task AsInternalExplicitFalse()
390+
{
391391
const string code = """
392392
393393
using AutomaticInterface;
@@ -401,7 +401,7 @@ public string AMethod(DemoClass? x, string y)
401401
}
402402
}
403403
404-
""";
404+
""";
405405
await Verify(Infrastructure.GenerateCode(code));
406406
}
407407
}

0 commit comments

Comments
 (0)