File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed
Microsoft.Toolkit.Mvvm.SourceGenerators/Attributes
UnitTests/UnitTests.NetCore Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,12 @@ public void Execute(GeneratorExecutionContext context)
34
34
/// </summary>
35
35
private void AddSourceCodeIfTypeIsNotPresent ( GeneratorExecutionContext context , string typeFullName )
36
36
{
37
- if ( context . Compilation . GetTypeByMetadataName ( typeFullName ) is not null )
37
+ // Check that the target attributes are not available in the consuming project. To ensure that
38
+ // this works fine both in .NET (Core) and .NET Standard implementations, we also need to check
39
+ // that the target types are defined in the reference assemblies for all target runtimes. This
40
+ // avoids issues on .NET Standard with Roslyn also seeing internal types from referenced assemblies.
41
+ if ( context . Compilation . GetTypeByMetadataName ( typeFullName ) is
42
+ { ContainingModule : { MetadataName : "netstandard.dll" or "System.Runtime.dll" } } )
38
43
{
39
44
return ;
40
45
}
Original file line number Diff line number Diff line change @@ -107,5 +107,25 @@ public partial class SampleModelWithINPCAndObservableProperties
107
107
[ ObservableProperty ]
108
108
private int y ;
109
109
}
110
+
111
+ [ TestCategory ( "Mvvm" ) ]
112
+ [ TestMethod ]
113
+ public void Test_INotifyPropertyChanged_WithGeneratedProperties_ExternalNetStandard20Assembly ( )
114
+ {
115
+ Assert . IsTrue ( typeof ( INotifyPropertyChanged ) . IsAssignableFrom ( typeof ( NetStandard . SampleModelWithINPCAndObservableProperties ) ) ) ;
116
+ Assert . IsFalse ( typeof ( INotifyPropertyChanging ) . IsAssignableFrom ( typeof ( NetStandard . SampleModelWithINPCAndObservableProperties ) ) ) ;
117
+
118
+ NetStandard . SampleModelWithINPCAndObservableProperties model = new ( ) ;
119
+ List < PropertyChangedEventArgs > eventArgs = new ( ) ;
120
+
121
+ model . PropertyChanged += ( s , e ) => eventArgs . Add ( e ) ;
122
+
123
+ model . X = 42 ;
124
+ model . Y = 66 ;
125
+
126
+ Assert . AreEqual ( eventArgs . Count , 2 ) ;
127
+ Assert . AreEqual ( eventArgs [ 0 ] . PropertyName , nameof ( NetStandard . SampleModelWithINPCAndObservableProperties . X ) ) ;
128
+ Assert . AreEqual ( eventArgs [ 1 ] . PropertyName , nameof ( NetStandard . SampleModelWithINPCAndObservableProperties . Y ) ) ;
129
+ }
110
130
}
111
131
}
Original file line number Diff line number Diff line change 10
10
<ProjectReference Include =" ..\..\Microsoft.Toolkit.Mvvm\Microsoft.Toolkit.Mvvm.csproj" />
11
11
<ProjectReference Include =" ..\..\Microsoft.Toolkit.Diagnostics\Microsoft.Toolkit.Diagnostics.csproj" />
12
12
<ProjectReference Include =" ..\..\Microsoft.Toolkit.Mvvm.SourceGenerators\Microsoft.Toolkit.Mvvm.SourceGenerators.csproj" OutputItemType =" Analyzer" ReferenceOutputAssembly =" false" PrivateAssets =" contentfiles;build" />
13
+ <ProjectReference Include =" ..\UnitTests.NetStandard\UnitTests.NetStandard.csproj" />
13
14
</ItemGroup >
14
15
15
16
<ItemGroup >
You can’t perform that action at this time.
0 commit comments