Skip to content

Commit

Permalink
Handle different access levels like private, protected, internal
Browse files Browse the repository at this point in the history
  • Loading branch information
Dương Kafka Đinh Hoàng committed May 13, 2024
1 parent 7b74d67 commit b41c762
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion BindableProps/BindableProps.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<PackageTags>source-generator;maui;net-standard;net-6;net-7;net-8;utility;helper</PackageTags>
<PackageProjectUrl>https://github.com/KafkaWannaFly/BindableProps</PackageProjectUrl>
<Version>1.4.2</Version>
<Version>1.4.3</Version>
<RepositoryUrl>https://github.com/KafkaWannaFly/BindableProps</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
16 changes: 14 additions & 2 deletions BindablePropsSG/Generators/BaseGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Text;
using BindablePropsSG.Utils;
Expand Down Expand Up @@ -86,6 +87,17 @@ protected virtual string ProcessClass(TypeDeclarationSyntax? typeDeclarationSynt
var namespaceSyntax = typeDeclarationSyntax.Parent as BaseNamespaceDeclarationSyntax;
var namespaceName = namespaceSyntax?.Name.ToString() ?? "global";

var accessLevelKeyWords = typeDeclarationSyntax?.Modifiers
.Where(
modifier => modifier.IsKind(SyntaxKind.PrivateKeyword)
|| modifier.IsKind(SyntaxKind.PublicKeyword)
|| modifier.IsKind(SyntaxKind.InternalKeyword)
|| modifier.IsKind(SyntaxKind.ProtectedKeyword)
)
.Select(modifier => modifier.Text) ?? ImmutableList<string>.Empty;
var accessLevel = string.Join(" ", accessLevelKeyWords);


var source = new StringBuilder($@"
#pragma warning disable
Expand All @@ -94,13 +106,13 @@ protected virtual string ProcessClass(TypeDeclarationSyntax? typeDeclarationSynt
namespace {namespaceName}
{{
public partial {typeDeclarationSyntax.Keyword.Text} {typeDeclarationSyntax.Identifier}
{accessLevel} partial {typeDeclarationSyntax.Keyword.Text} {typeDeclarationSyntax.Identifier}

Check warning on line 109 in BindablePropsSG/Generators/BaseGenerator.cs

View workflow job for this annotation

GitHub Actions / Unit Test

Dereference of a possibly null reference.

Check warning on line 109 in BindablePropsSG/Generators/BaseGenerator.cs

View workflow job for this annotation

GitHub Actions / Unit Test

Dereference of a possibly null reference.

Check warning on line 109 in BindablePropsSG/Generators/BaseGenerator.cs

View workflow job for this annotation

GitHub Actions / Unit Test

Dereference of a possibly null reference.

Check warning on line 109 in BindablePropsSG/Generators/BaseGenerator.cs

View workflow job for this annotation

GitHub Actions / Unit Test

Dereference of a possibly null reference.
{{
");

foreach (var (syntax, symbol) in syntaxSymbols)
{
ProcessField(source, typeDeclarationSyntax, syntax, symbol);
ProcessField(source, typeDeclarationSyntax!, syntax, symbol);
}

source.Append(@$"
Expand Down

0 comments on commit b41c762

Please sign in to comment.