@@ -193,6 +193,92 @@ public object? A
193
193
VerifyGenerateSources ( source , new [ ] { new ObservablePropertyGenerator ( ) } , ( "MyApp.MyViewModel.g.cs" , result ) ) ;
194
194
}
195
195
196
+ [ TestMethod ]
197
+ public void ObservablePropertyWithinGenericAndNestedTypes ( )
198
+ {
199
+ string source = """
200
+ using System.ComponentModel;
201
+ using CommunityToolkit.Mvvm.ComponentModel;
202
+
203
+ #nullable enable
204
+
205
+ namespace MyApp;
206
+
207
+ partial class Foo
208
+ {
209
+ partial class MyViewModel<T> : ObservableObject
210
+ {
211
+ [ObservableProperty]
212
+ private string? a;
213
+ }
214
+ }
215
+ """ ;
216
+
217
+ string result = """
218
+ // <auto-generated/>
219
+ #pragma warning disable
220
+ #nullable enable
221
+ namespace MyApp
222
+ {
223
+ partial class Foo
224
+ {
225
+ partial class MyViewModel<T>
226
+ {
227
+ /// <inheritdoc cref="a"/>
228
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.1.0.0")]
229
+ [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
230
+ public string? A
231
+ {
232
+ get => a;
233
+ set
234
+ {
235
+ if (!global::System.Collections.Generic.EqualityComparer<string?>.Default.Equals(a, value))
236
+ {
237
+ OnAChanging(value);
238
+ OnAChanging(default, value);
239
+ OnPropertyChanging(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangingArgs.A);
240
+ a = value;
241
+ OnAChanged(value);
242
+ OnAChanged(default, value);
243
+ OnPropertyChanged(global::CommunityToolkit.Mvvm.ComponentModel.__Internals.__KnownINotifyPropertyChangedArgs.A);
244
+ }
245
+ }
246
+ }
247
+
248
+ /// <summary>Executes the logic for when <see cref="A"/> is changing.</summary>
249
+ /// <param name="value">The new property value being set.</param>
250
+ /// <remarks>This method is invoked right before the value of <see cref="A"/> is changed.</remarks>
251
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.1.0.0")]
252
+ partial void OnAChanging(string? value);
253
+ /// <summary>Executes the logic for when <see cref="A"/> is changing.</summary>
254
+ /// <param name="oldValue">The previous property value that is being replaced.</param>
255
+ /// <param name="newValue">The new property value being set.</param>
256
+ /// <remarks>This method is invoked right before the value of <see cref="A"/> is changed.</remarks>
257
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.1.0.0")]
258
+ partial void OnAChanging(string? oldValue, string? newValue);
259
+ /// <summary>Executes the logic for when <see cref="A"/> just changed.</summary>
260
+ /// <param name="value">The new property value that was set.</param>
261
+ /// <remarks>This method is invoked right after the value of <see cref="A"/> is changed.</remarks>
262
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.1.0.0")]
263
+ partial void OnAChanged(string? value);
264
+ /// <summary>Executes the logic for when <see cref="A"/> just changed.</summary>
265
+ /// <param name="oldValue">The previous property value that was replaced.</param>
266
+ /// <param name="newValue">The new property value that was set.</param>
267
+ /// <remarks>This method is invoked right after the value of <see cref="A"/> is changed.</remarks>
268
+ [global::System.CodeDom.Compiler.GeneratedCode("CommunityToolkit.Mvvm.SourceGenerators.ObservablePropertyGenerator", "8.1.0.0")]
269
+ partial void OnAChanged(string? oldValue, string? newValue);
270
+ }
271
+ }
272
+ }
273
+ """ ;
274
+
275
+ #if ROSLYN_4_3_1_OR_GREATER
276
+ VerifyGenerateSources ( source , new [ ] { new ObservablePropertyGenerator ( ) } , ( "MyApp.Foo+MyViewModel`1.g.cs" , result ) ) ;
277
+ #else
278
+ VerifyGenerateSources ( source , new [ ] { new ObservablePropertyGenerator ( ) } , ( "MyApp.Foo.MyViewModel_1.g.cs" , result ) ) ;
279
+ #endif
280
+ }
281
+
196
282
/// <summary>
197
283
/// Generates the requested sources
198
284
/// </summary>
@@ -212,7 +298,7 @@ from assembly in AppDomain.CurrentDomain.GetAssemblies()
212
298
let reference = MetadataReference . CreateFromFile ( assembly . Location )
213
299
select reference ;
214
300
215
- SyntaxTree syntaxTree = CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp11 ) ) ;
301
+ SyntaxTree syntaxTree = CSharpSyntaxTree . ParseText ( source , CSharpParseOptions . Default . WithLanguageVersion ( LanguageVersion . CSharp10 ) ) ;
216
302
217
303
// Create a syntax tree with the input source
218
304
CSharpCompilation compilation = CSharpCompilation . Create (
0 commit comments