Skip to content

Commit 166bb4d

Browse files
Fix bug where x:Static argument is treated as member of 'SystemParameters' by mistake (#680)
* Fix bug where x:Static argument is treated as member of 'SystemParameters' by mistake * Move type checking to GetBamlIdBasedOnSystemResourceKeyId() * Use Enum.TryParse instead * Simplify code * Fixing build --------- Co-authored-by: Rishabh Chauhan <[email protected]>
1 parent a0121f7 commit 166bb4d

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/SystemResourceKey.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,6 @@ internal static short GetBamlIdBasedOnSystemResourceKeyId(Type targetType, strin
366366
bool isKey = false;
367367
bool found = true;
368368

369-
// Initialization needed to keep compiler happy!
370-
SystemResourceKeyID srkId = SystemResourceKeyID.InternalSystemColorsStart;
371-
372369
if (memberName.EndsWith("Key", false, TypeConverterHelper.InvariantEnglishUS))
373370
{
374371
srkField = memberName.Remove(memberName.Length - 3);
@@ -386,17 +383,15 @@ internal static short GetBamlIdBasedOnSystemResourceKeyId(Type targetType, strin
386383
{
387384
srkField = memberName;
388385
}
386+
#if PBTCOMPILER
387+
388+
found &= targetType.Assembly == XamlTypeMapper.AssemblyPF &&
389+
targetType.FullName == "System.Windows.SystemParameters";
390+
391+
#endif
389392

390-
try
391-
{
392-
srkId = (SystemResourceKeyID)Enum.Parse(typeof(SystemResourceKeyID), srkField);
393-
}
394-
catch (ArgumentException)
395-
{
396-
found = false;
397-
}
398-
399-
if (found)
393+
if (found &&
394+
Enum.TryParse(srkField, out SystemResourceKeyID srkId))
400395
{
401396
bool isExtended = ((short)srkId > SystemResourceKeyIDExtendedStart &&
402397
(short)srkId < SystemResourceKeyIDExtendedEnd);

0 commit comments

Comments
 (0)