Skip to content

Commit bb8e2be

Browse files
committed
Fixed Init and private set properties
1 parent bfaab78 commit bb8e2be

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

nuget/Sqlite_net.SourceGenerator/SQLiteFastColumnSetterGenerator.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ static bool HasBaseClass (ClassDeclarationSyntax classDecl)
124124
var currentType = classSymbol;
125125
while (currentType != null) {
126126
foreach (var member in currentType.GetMembers ().OfType<IPropertySymbol> ()) {
127-
if (!member.IsReadOnly && !member.IsStatic && !member.IsIndexer && (member.DeclaredAccessibility != Accessibility.Private && member.DeclaredAccessibility != Accessibility.Protected) ) {
127+
if (!member.IsReadOnly && !member.IsStatic && !member.IsIndexer &&
128+
(member.DeclaredAccessibility != Accessibility.Private && member.DeclaredAccessibility != Accessibility.Protected) &&
129+
(member.SetMethod?.DeclaredAccessibility != Accessibility.Private && member.SetMethod?.DeclaredAccessibility != Accessibility.Protected && member.SetMethod?.IsInitOnly != true)) {
128130
var ignore = member.GetAttributes ()
129131
.Any (attr => IsIgnoreAttribute (attr.AttributeClass));
130132

tests/SQLite.Tests/SQLite.Tests.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<TargetFramework>net8.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
7-
7+
<LangVersion>9</LangVersion>
88
</PropertyGroup>
99

1010
<ItemGroup>
1111
<PackageReference Include="AltCover" Version="8.7.3" />
1212
<PackageReference Include="NUnit" Version="3.12.0" />
1313
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.0" />
1515
</ItemGroup>
1616

1717
<!-- SourceGenerator -->

tests/SQLite.Tests/SourceGeneratorTest.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public class OuterTestSetter
4646

4747
[Obsolete]
4848
public string Obsolete { get; set; }
49+
50+
public string PrivateSet { get; private set; }
51+
52+
public string Init { get; init; }
4953
}
5054

5155
public class OuterTestDb : SQLiteConnection
@@ -266,6 +270,28 @@ public void SqliteInitializer_OuterTestSetter_StaticProperty_NotRegistered ()
266270
}
267271
}
268272

273+
[Test]
274+
public void SqliteInitializer_OuterTestSetter_PrivateSet_NotRegistered ()
275+
{
276+
if (!SQLite.FastColumnSetter.customSetter.TryGetValue ((typeof (OuterTestSetter), nameof (OuterTestSetter.PrivateSet)), out var setter)) {
277+
Assert.IsTrue (true, "Private Set properties Should not be registered");
278+
}
279+
else {
280+
Assert.Fail ("Private Set properties Should not be registered");
281+
}
282+
}
283+
284+
[Test]
285+
public void SqliteInitializer_OuterTestSetter_Init_NotRegistered ()
286+
{
287+
if (!SQLite.FastColumnSetter.customSetter.TryGetValue ((typeof (OuterTestSetter), nameof (OuterTestSetter.Init)), out var setter)) {
288+
Assert.IsTrue (true, "Init properties Should not be registered");
289+
}
290+
else {
291+
Assert.Fail ("Init properties Should not be registered");
292+
}
293+
}
294+
269295
[Test]
270296
public void SqliteInitializer_OuterTestSetter ()
271297
{

0 commit comments

Comments
 (0)