Skip to content

Commit 3e5623f

Browse files
Fixxing issue with missing AccessorAccess before Source Generator Property
1 parent acb3180 commit 3e5623f

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

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

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,29 @@ public virtual void OnPropertyChanged([System.Runtime.CompilerServices.CallerMem
201201
}");
202202
}
203203

204-
// Helper to convert AccessorAccessibility to C# keyword (empty string means public)
205-
static string ToAccessorString(object accessor)
204+
// Helper to convert AccessorAccessibility to C# keyword for property (never empty)
205+
static string ToPropertyAccessibilityString(string access)
206206
{
207-
var value = accessor?.ToString() ?? "Public";
208-
return value switch
207+
return access switch
209208
{
210-
"Public" => "",
209+
"Public" => "public ",
211210
"Private" => "private ",
212211
"Protected" => "protected ",
213212
"Internal" => "internal ",
214213
"ProtectedInternal" => "protected internal ",
215214
"PrivateProtected" => "private protected ",
216-
_ => ""
215+
_ => "public "
217216
};
218217
}
219218

219+
// Helper to convert AccessorAccessibility to C# keyword for accessor (empty if matches property)
220+
static string ToAccessorAccessibilityString(string accessor, string property)
221+
{
222+
if (string.Equals(accessor, property, System.StringComparison.OrdinalIgnoreCase) || accessor == null)
223+
return "";
224+
return ToPropertyAccessibilityString(accessor);
225+
}
226+
220227
// Helper to rank accessibilities for comparison
221228
static int GetAccessibilityRank(string access)
222229
{
@@ -277,10 +284,13 @@ static string GetWidestAccessibility(object getter, object setter)
277284
var getter = args.Length > 4 ? args[4].Value : null;
278285
var setter = args.Length > 5 ? args[5].Value : null;
279286

280-
// If getter/setter are not specified, default to "Public"
281-
var getterStr = ToAccessorString(getter ?? "Public");
282-
var setterStr = ToAccessorString(setter ?? "Public");
283-
var propertyAccessibilityStr = ToAccessorString(GetWidestAccessibility(getter ?? "Public", setter ?? "Public"));
287+
// Get string values for getter/setter, defaulting to "Public"
288+
string getterValue = (getter ?? "Public").ToString();
289+
string setterValue = (setter ?? "Public").ToString();
290+
string propertyAccess = GetWidestAccessibility(getterValue, setterValue);
291+
string propertyAccessibilityStr = ToPropertyAccessibilityString(propertyAccess);
292+
string getterStr = ToAccessorAccessibilityString(getterValue, propertyAccess);
293+
string setterStr = ToAccessorAccessibilityString(setterValue, propertyAccess);
284294

285295
var lockerArg = threadSafe ? "_Locker" : "null";
286296
var notifyArg = notify ? "true" : "false";
@@ -347,10 +357,13 @@ static string GetWidestAccessibility(object getter, object setter)
347357
var getter = args.Length > 2 ? args[2].Value : null;
348358
var setter = args.Length > 3 ? args[3].Value : null;
349359

350-
// If getter/setter are not specified, default to "Public"
351-
var getterStr = ToAccessorString(getter ?? "Public");
352-
var setterStr = ToAccessorString(setter ?? "Public");
353-
var propertyAccessibilityStr = ToAccessorString(GetWidestAccessibility(getter ?? "Public", setter ?? "Public"));
360+
// Get string values for getter/setter, defaulting to "Public"
361+
string getterValue = (getter ?? "Public").ToString();
362+
string setterValue = (setter ?? "Public").ToString();
363+
string propertyAccess = GetWidestAccessibility(getterValue, setterValue);
364+
string propertyAccessibilityStr = ToPropertyAccessibilityString(propertyAccess);
365+
string getterStr = ToAccessorAccessibilityString(getterValue, propertyAccess);
366+
string setterStr = ToAccessorAccessibilityString(setterValue, propertyAccess);
354367

355368
var lockerArg = threadSafe ? "_Locker" : "null";
356369
if (readOnly)

0 commit comments

Comments
 (0)