File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 3
3
// See the LICENSE file in the project root for more information.
4
4
5
5
using System ;
6
+ #if ! NET6_0_OR_GREATER
7
+ using System . Collections . Generic ;
8
+ using System . Linq ;
9
+ #endif
10
+ using System . Reflection ;
6
11
using CommunityToolkit . Mvvm . ComponentModel ;
7
12
using CommunityToolkit . Mvvm . Messaging ;
8
13
using CommunityToolkit . Mvvm . Messaging . Messages ;
9
14
using Microsoft . VisualStudio . TestTools . UnitTesting ;
10
15
16
+ #pragma warning disable CS0618
17
+
11
18
namespace CommunityToolkit . Mvvm . UnitTests ;
12
19
13
20
[ TestClass ]
@@ -85,6 +92,23 @@ public void Test_ObservableRecipient_Broadcast(Type type)
85
92
Assert . AreEqual ( message . PropertyName , nameof ( SomeRecipient < int > . Data ) ) ;
86
93
}
87
94
95
+ [ TestMethod ]
96
+ public void Test_IRecipient_VerifyTrimmingAnnotation ( )
97
+ {
98
+ #if NET6_0_OR_GREATER
99
+ System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembersAttribute ? attribute =
100
+ typeof ( Messaging . __Internals . __IMessengerExtensions )
101
+ . GetCustomAttribute < System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembersAttribute > ( ) ;
102
+
103
+ Assert . IsNotNull ( attribute ) ;
104
+ Assert . AreEqual ( System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicMethods , attribute . MemberTypes ) ;
105
+ #else
106
+ IEnumerable < Attribute > attributes = typeof ( Messaging . __Internals . __IMessengerExtensions ) . GetCustomAttributes ( ) ;
107
+
108
+ Assert . IsFalse ( attributes . Any ( static a => a . GetType ( ) . Name is "DynamicallyAccessedMembersAttribute" ) ) ;
109
+ #endif
110
+ }
111
+
88
112
public class SomeRecipient < T > : ObservableRecipient
89
113
{
90
114
public SomeRecipient ( )
Original file line number Diff line number Diff line change 12
12
using CommunityToolkit . Mvvm . ComponentModel ;
13
13
using Microsoft . VisualStudio . TestTools . UnitTesting ;
14
14
15
+ #pragma warning disable CS0618
16
+
15
17
namespace CommunityToolkit . Mvvm . UnitTests ;
16
18
17
19
[ TestClass ]
@@ -477,6 +479,23 @@ public void Test_ObservableRecipient_ValidationOnNonValidatableProperties_WithFa
477
479
validationFunc ( viewmodel . GetType ( ) ) ( viewmodel ) ;
478
480
}
479
481
482
+ [ TestMethod ]
483
+ public void Test_ObservableValidator_VerifyTrimmingAnnotation ( )
484
+ {
485
+ #if NET6_0_OR_GREATER
486
+ System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembersAttribute ? attribute =
487
+ typeof ( ComponentModel . __Internals . __ObservableValidatorExtensions )
488
+ . GetCustomAttribute < System . Diagnostics . CodeAnalysis . DynamicallyAccessedMembersAttribute > ( ) ;
489
+
490
+ Assert . IsNotNull ( attribute ) ;
491
+ Assert . AreEqual ( System . Diagnostics . CodeAnalysis . DynamicallyAccessedMemberTypes . PublicMethods , attribute . MemberTypes ) ;
492
+ #else
493
+ IEnumerable < Attribute > attributes = typeof ( ComponentModel . __Internals . __ObservableValidatorExtensions ) . GetCustomAttributes ( ) ;
494
+
495
+ Assert . IsFalse ( attributes . Any ( static a => a . GetType ( ) . Name is "DynamicallyAccessedMembersAttribute" ) ) ;
496
+ #endif
497
+ }
498
+
480
499
public class Person : ObservableValidator
481
500
{
482
501
private string ? name ;
You can’t perform that action at this time.
0 commit comments