Skip to content

Commit 0febec9

Browse files
Now only added _Locker for non static fields
1 parent 030a474 commit 0febec9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/ThunderDesign.Net-PCL.SourceGenerators/UnifiedPropertyGenerator.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ private static void GenerateInfrastructureMembers(
295295
{
296296
// Check if we have any static property fields
297297
bool hasStaticProperties = propertyFields.Any(p => p.FieldSymbol.IsStatic);
298+
299+
// Check if we have any non-static fields that need the instance locker
300+
bool hasNonStaticFields = bindableFields.Count > 0 || propertyFields.Any(p => !p.FieldSymbol.IsStatic);
298301

299302
// Add event if needed
300303
if (bindableFields.Count > 0 && !implementsINotify &&
@@ -303,8 +306,8 @@ private static void GenerateInfrastructureMembers(
303306
source.AppendLine(" public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;");
304307
}
305308

306-
// Add _Locker if needed
307-
if ((!inheritsThreadObject) && !PropertyGeneratorHelpers.FieldExists(classSymbol, "_Locker"))
309+
// Add _Locker if needed (only for non-static fields)
310+
if (hasNonStaticFields && (!inheritsThreadObject) && !PropertyGeneratorHelpers.FieldExists(classSymbol, "_Locker"))
308311
{
309312
source.AppendLine(" protected readonly object _Locker = new object();");
310313
}

0 commit comments

Comments
 (0)