File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed
src/ThunderDesign.Net-PCL.SourceGenerators Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments