Skip to content

Commit

Permalink
merged crwsolutions branch
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianSauer committed Nov 29, 2024
2 parents edc3965 + 6edf896 commit 2920be4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<EnableNETAnalyzers>True</EnableNETAnalyzers>
<AnalysisLevel>latest-Recommended</AnalysisLevel>
<Version>5.0.2</Version>
<Version>5.0.3</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>1701;1702;NU5128</NoWarn>
<PackageReleaseNotes>Use ForAttributeWithMetadataName to improve performance</PackageReleaseNotes>
<PackageReleaseNotes>Query members only once. Small optimization.</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='DebugGenerator|AnyCPU'">
Expand Down
44 changes: 17 additions & 27 deletions AutomaticInterface/AutomaticInterface/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ is not ClassDeclarationSyntax classSyntax

interfaceGenerator.AddClassDocumentation(GetDocumentationForClass(classSyntax));
interfaceGenerator.AddGeneric(GetGeneric(classSyntax));
AddPropertiesToInterface(typeSymbol, interfaceGenerator);
AddMethodsToInterface(typeSymbol, interfaceGenerator);
AddEventsToInterface(typeSymbol, interfaceGenerator);

var members = typeSymbol
.GetAllMembers()
.Where(x => x.DeclaredAccessibility == Accessibility.Public)
.Where(x => !x.IsStatic)
.Where(x => !HasIgnoreAttribute(x))
.ToList();

AddPropertiesToInterface(members, interfaceGenerator);
AddMethodsToInterface(members, interfaceGenerator);
AddEventsToInterface(members, interfaceGenerator);

var generatedCode = interfaceGenerator.Build();

Expand All @@ -70,19 +78,12 @@ private static string GetNameSpace(ISymbol typeSymbol)
: customNs!;
}

private static void AddMethodsToInterface(
ITypeSymbol classSymbol,
InterfaceBuilder codeGenerator
)
private static void AddMethodsToInterface(List<ISymbol> members, InterfaceBuilder codeGenerator)
{
classSymbol
.GetAllMembers()
members
.Where(x => x.Kind == SymbolKind.Method)
.OfType<IMethodSymbol>()
.Where(x => x.DeclaredAccessibility == Accessibility.Public)
.Where(x => x.MethodKind == MethodKind.Ordinary)
.Where(x => !x.IsStatic)
.Where(x => !HasIgnoreAttribute(x))
.Where(x => x.ContainingType.Name != nameof(Object))
.Where(x => !HasIgnoreAttribute(x))
.GroupBy(x => x.ToDisplayString(FullyQualifiedDisplayFormat))
Expand Down Expand Up @@ -171,18 +172,11 @@ private static bool IsNullable(ITypeSymbol typeSymbol)
return false;
}

private static void AddEventsToInterface(
ITypeSymbol classSymbol,
InterfaceBuilder codeGenerator
)
private static void AddEventsToInterface(List<ISymbol> members, InterfaceBuilder codeGenerator)
{
classSymbol
.GetAllMembers()
members
.Where(x => x.Kind == SymbolKind.Event)
.OfType<IEventSymbol>()
.Where(x => x.DeclaredAccessibility == Accessibility.Public)
.Where(x => !x.IsStatic)
.Where(x => !HasIgnoreAttribute(x))
.GroupBy(x => x.ToDisplayString(FullyQualifiedDisplayFormat))
.Select(g => g.First())
.ToList()
Expand Down Expand Up @@ -252,18 +246,14 @@ private static string GetRefKind(IParameterSymbol x)
}

private static void AddPropertiesToInterface(
ITypeSymbol classSymbol,
List<ISymbol> members,
InterfaceBuilder interfaceGenerator
)
{
classSymbol
.GetAllMembers()
members
.Where(x => x.Kind == SymbolKind.Property)
.OfType<IPropertySymbol>()
.Where(x => x.DeclaredAccessibility == Accessibility.Public)
.Where(x => !x.IsStatic)
.Where(x => !x.IsIndexer)
.Where(x => !HasIgnoreAttribute(x))
.GroupBy(x => x.Name)
.Select(g => g.First())
.ToList()
Expand Down
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,18 @@ Should be simply a build and run Tests

## Changelog

### 5.0.0
### 5.0.3

- Query members only once. Small optimization. Thanks, @crwsolutions!

### 5.0.2

- Fully qualify type references; remove usings . Thanks, @simonmckenzie!

### 5.0.1

- Sync DemoClass and actual generated code with README. Thanks, @crwsolutions!
- Removed manual attribute in TestNuget project. Thanks, @crwsolutions!
- Removed manual attribute in TestNuget project. Thanks, @crwsolutions!

### 5.0.0

Expand Down

0 comments on commit 2920be4

Please sign in to comment.