Skip to content

Commit 7f5bd6c

Browse files
committed
Switched generated command field to concrete type
Doing this enables the JIT to devirtualize function calls through the property
1 parent 5ba929f commit 7f5bd6c

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

Microsoft.Toolkit.Mvvm.SourceGenerators/Input/ICommandGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private static IEnumerable<MemberDeclarationSyntax> CreateCommandMembers(Generat
150150
// private <COMMAND_TYPE>? <COMMAND_FIELD_NAME>;
151151
FieldDeclarationSyntax fieldDeclaration =
152152
FieldDeclaration(
153-
VariableDeclaration(NullableType(IdentifierName(commandInterfaceTypeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))))
153+
VariableDeclaration(NullableType(IdentifierName(commandClassTypeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))))
154154
.AddVariables(VariableDeclarator(Identifier(fieldName))))
155155
.AddModifiers(Token(SyntaxKind.PrivateKeyword))
156156
.AddAttributeLists(AttributeList(SingletonSeparatedList(

UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void Test_AlsoNotifyForAttribute_Events()
6262
{
6363
var model = new DependentPropertyModel();
6464

65-
List<string> propertyNames = new();
65+
List<string?> propertyNames = new();
6666

6767
model.PropertyChanged += (s, e) => propertyNames.Add(e.PropertyName);
6868

@@ -76,27 +76,27 @@ public void Test_AlsoNotifyForAttribute_Events()
7676
[TestMethod]
7777
public void Test_ValidationAttributes()
7878
{
79-
var nameProperty = typeof(MyFormViewModel).GetProperty(nameof(MyFormViewModel.Name));
79+
var nameProperty = typeof(MyFormViewModel).GetProperty(nameof(MyFormViewModel.Name))!;
8080

8181
Assert.IsNotNull(nameProperty.GetCustomAttribute<RequiredAttribute>());
8282
Assert.IsNotNull(nameProperty.GetCustomAttribute<MinLengthAttribute>());
83-
Assert.AreEqual(nameProperty.GetCustomAttribute<MinLengthAttribute>().Length, 1);
83+
Assert.AreEqual(nameProperty.GetCustomAttribute<MinLengthAttribute>()!.Length, 1);
8484
Assert.IsNotNull(nameProperty.GetCustomAttribute<MaxLengthAttribute>());
85-
Assert.AreEqual(nameProperty.GetCustomAttribute<MaxLengthAttribute>().Length, 100);
85+
Assert.AreEqual(nameProperty.GetCustomAttribute<MaxLengthAttribute>()!.Length, 100);
8686

87-
var ageProperty = typeof(MyFormViewModel).GetProperty(nameof(MyFormViewModel.Age));
87+
var ageProperty = typeof(MyFormViewModel).GetProperty(nameof(MyFormViewModel.Age))!;
8888

8989
Assert.IsNotNull(ageProperty.GetCustomAttribute<RangeAttribute>());
90-
Assert.AreEqual(ageProperty.GetCustomAttribute<RangeAttribute>().Minimum, 0);
91-
Assert.AreEqual(ageProperty.GetCustomAttribute<RangeAttribute>().Maximum, 120);
90+
Assert.AreEqual(ageProperty.GetCustomAttribute<RangeAttribute>()!.Minimum, 0);
91+
Assert.AreEqual(ageProperty.GetCustomAttribute<RangeAttribute>()!.Maximum, 120);
9292

93-
var emailProperty = typeof(MyFormViewModel).GetProperty(nameof(MyFormViewModel.Email));
93+
var emailProperty = typeof(MyFormViewModel).GetProperty(nameof(MyFormViewModel.Email))!;
9494

9595
Assert.IsNotNull(emailProperty.GetCustomAttribute<EmailAddressAttribute>());
9696

97-
var comboProperty = typeof(MyFormViewModel).GetProperty(nameof(MyFormViewModel.IfThisWorksThenThatsGreat));
97+
var comboProperty = typeof(MyFormViewModel).GetProperty(nameof(MyFormViewModel.IfThisWorksThenThatsGreat))!;
9898

99-
TestValidationAttribute? testAttribute = comboProperty.GetCustomAttribute<TestValidationAttribute>();
99+
TestValidationAttribute testAttribute = comboProperty.GetCustomAttribute<TestValidationAttribute>()!;
100100

101101
Assert.IsNotNull(testAttribute);
102102
Assert.IsNull(testAttribute.O);

0 commit comments

Comments
 (0)