Skip to content

Commit a85e699

Browse files
committed
Upgrade to C# 9.0 and use logical pattern matching.
1 parent edc5b7b commit a85e699

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

Microsoft.Toolkit.Uwp.UI/Microsoft.Toolkit.Uwp.UI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>uap10.0.17763</TargetFrameworks>
5-
<LangVersion>8.0</LangVersion>
5+
<LangVersion>9.0</LangVersion>
66
<Title>Windows Community Toolkit UI</Title>
77
<Description>
88
This library provides UI components, such as XAML extensions, helpers, converters and more. It is part of the Windows Community Toolkit.

Microsoft.Toolkit.Uwp.UI/Triggers/IsEqualStateTrigger.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ internal static bool AreValuesEqual(object value1, object value2, bool convertTy
6767
}
6868

6969
// If they are the same type but fail with Equals check, don't bother with conversion.
70-
if (value1 != null && value2 != null && value1.GetType() != value2.GetType() && convertType)
70+
if (value1 is not null && value2 is not null && convertType
71+
&& value1.GetType() != value2.GetType())
7172
{
7273
// Try the conversion in both ways:
7374
return ConvertTypeEquals(value1, value2) || ConvertTypeEquals(value2, value1);
@@ -94,20 +95,13 @@ private static bool ConvertTypeEquals(object value1, object value2)
9495
private static object ConvertToEnum(Type enumType, object value)
9596
{
9697
// value cannot be the same type of enum now
97-
if (value is string str)
98+
return value switch
9899
{
99-
return Enum.TryParse(enumType, str, out var e) ? e : null;
100-
}
101-
102-
if (value is int || value is uint
103-
|| value is byte || value is sbyte
104-
|| value is long || value is ulong
105-
|| value is short || value is ushort)
106-
{
107-
return Enum.ToObject(enumType, value);
108-
}
109-
110-
return null;
100+
string str => Enum.TryParse(enumType, str, out var e) ? e : null,
101+
int or uint or byte or sbyte or long or ulong or short or ushort
102+
=> Enum.ToObject(enumType, value),
103+
_ => null
104+
};
111105
}
112106
}
113107
}

0 commit comments

Comments
 (0)