Skip to content

Commit 13a9149

Browse files
committed
Lower C# version requirement to 8 for all generators
1 parent 6fb377b commit 13a9149

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

CommunityToolkit.Mvvm.SourceGenerators/ComponentModel/ObservablePropertyGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
3333
// This ensures that users not using any of the source generators won't be broken when upgrading to this new version.
3434
IncrementalValueProvider<bool> isGeneratorSupported =
3535
context.ParseOptionsProvider
36-
.Select(static (item, _) => item is CSharpParseOptions { LanguageVersion: >= LanguageVersion.CSharp9 });
36+
.Select(static (item, _) => item is CSharpParseOptions { LanguageVersion: >= LanguageVersion.CSharp8 });
3737

3838
// Emit the diagnostic, if needed
3939
context.ReportDiagnosticsIsNotSupported(isGeneratorSupported, Diagnostic.Create(UnsupportedCSharpLanguageVersionError, null));

CommunityToolkit.Mvvm.SourceGenerators/ComponentModel/TransitiveMembersGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
7676
// Validate the language version
7777
IncrementalValueProvider<bool> isGeneratorSupported =
7878
context.ParseOptionsProvider
79-
.Select(static (item, _) => item is CSharpParseOptions { LanguageVersion: >= LanguageVersion.CSharp9 });
79+
.Select(static (item, _) => item is CSharpParseOptions { LanguageVersion: >= LanguageVersion.CSharp8 });
8080

8181
// Get all class declarations
8282
IncrementalValuesProvider<INamedTypeSymbol> typeSymbols =

CommunityToolkit.Mvvm.SourceGenerators/EmbeddedResources/INotifyPropertyChanged.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ protected bool SetProperty<TModel, T>(T oldValue, T newValue, global::System.Col
272272
/// </remarks>
273273
protected bool SetPropertyAndNotifyOnCompletion([global::System.Diagnostics.CodeAnalysis.NotNull] ref TaskNotifier? taskNotifier, global::System.Threading.Tasks.Task? newValue, [global::System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
274274
{
275-
return SetPropertyAndNotifyOnCompletion(taskNotifier ??= new TaskNotifier(), newValue, static _ => { }, propertyName);
275+
return SetPropertyAndNotifyOnCompletion(taskNotifier ??= new TaskNotifier(), newValue, null, propertyName);
276276
}
277277

278278
/// <summary>
@@ -330,7 +330,7 @@ protected bool SetPropertyAndNotifyOnCompletion([global::System.Diagnostics.Code
330330
/// </remarks>
331331
protected bool SetPropertyAndNotifyOnCompletion<T>([global::System.Diagnostics.CodeAnalysis.NotNull] ref TaskNotifier<T>? taskNotifier, global::System.Threading.Tasks.Task<T>? newValue, [global::System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
332332
{
333-
return SetPropertyAndNotifyOnCompletion(taskNotifier ??= new TaskNotifier<T>(), newValue, static _ => { }, propertyName);
333+
return SetPropertyAndNotifyOnCompletion(taskNotifier ??= new TaskNotifier<T>(), newValue, null, propertyName);
334334
}
335335

336336
/// <summary>
@@ -360,10 +360,10 @@ protected bool SetPropertyAndNotifyOnCompletion<T>([global::System.Diagnostics.C
360360
/// <typeparam name="TTask">The type of <see cref="global::System.Threading.Tasks.Task"/> to set and monitor.</typeparam>
361361
/// <param name="taskNotifier">The field notifier.</param>
362362
/// <param name="newValue">The property's value after the change occurred.</param>
363-
/// <param name="callback">A callback to invoke to update the property value.</param>
363+
/// <param name="callback">(optional) A callback to invoke to update the property value.</param>
364364
/// <param name="propertyName">(optional) The name of the property that changed.</param>
365365
/// <returns><see langword="true"/> if the property was changed, <see langword="false"/> otherwise.</returns>
366-
private bool SetPropertyAndNotifyOnCompletion<TTask>(ITaskNotifier<TTask> taskNotifier, TTask? newValue, global::System.Action<TTask?> callback, [global::System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
366+
private bool SetPropertyAndNotifyOnCompletion<TTask>(ITaskNotifier<TTask> taskNotifier, TTask? newValue, global::System.Action<TTask?>? callback, [global::System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
367367
where TTask : global::System.Threading.Tasks.Task
368368
{
369369
if (ReferenceEquals(taskNotifier.Task, newValue))
@@ -379,7 +379,10 @@ private bool SetPropertyAndNotifyOnCompletion<TTask>(ITaskNotifier<TTask> taskNo
379379

380380
if (isAlreadyCompletedOrNull)
381381
{
382-
callback(newValue);
382+
if (callback != null)
383+
{
384+
callback(newValue);
385+
}
383386

384387
return true;
385388
}
@@ -399,7 +402,10 @@ async void MonitorTask()
399402
OnPropertyChanged(propertyName);
400403
}
401404

402-
callback(newValue);
405+
if (callback != null)
406+
{
407+
callback(newValue);
408+
}
403409
}
404410

405411
MonitorTask();

CommunityToolkit.Mvvm.SourceGenerators/EmbeddedResources/ObservableObject.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ protected bool SetProperty<TModel, T>(T oldValue, T newValue, global::System.Col
313313
/// </remarks>
314314
protected bool SetPropertyAndNotifyOnCompletion([global::System.Diagnostics.CodeAnalysis.NotNull] ref TaskNotifier? taskNotifier, global::System.Threading.Tasks.Task? newValue, [global::System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
315315
{
316-
return SetPropertyAndNotifyOnCompletion(taskNotifier ??= new TaskNotifier(), newValue, static _ => { }, propertyName);
316+
return SetPropertyAndNotifyOnCompletion(taskNotifier ??= new TaskNotifier(), newValue, null, propertyName);
317317
}
318318

319319
/// <summary>
@@ -374,7 +374,7 @@ protected bool SetPropertyAndNotifyOnCompletion([global::System.Diagnostics.Code
374374
/// </remarks>
375375
protected bool SetPropertyAndNotifyOnCompletion<T>([global::System.Diagnostics.CodeAnalysis.NotNull] ref TaskNotifier<T>? taskNotifier, global::System.Threading.Tasks.Task<T>? newValue, [global::System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
376376
{
377-
return SetPropertyAndNotifyOnCompletion(taskNotifier ??= new TaskNotifier<T>(), newValue, static _ => { }, propertyName);
377+
return SetPropertyAndNotifyOnCompletion(taskNotifier ??= new TaskNotifier<T>(), newValue, null, propertyName);
378378
}
379379

380380
/// <summary>
@@ -406,10 +406,10 @@ protected bool SetPropertyAndNotifyOnCompletion<T>([global::System.Diagnostics.C
406406
/// <typeparam name="TTask">The type of <see cref="global::System.Threading.Tasks.Task"/> to set and monitor.</typeparam>
407407
/// <param name="taskNotifier">The field notifier.</param>
408408
/// <param name="newValue">The property's value after the change occurred.</param>
409-
/// <param name="callback">A callback to invoke to update the property value.</param>
409+
/// <param name="callback">(optional) A callback to invoke to update the property value.</param>
410410
/// <param name="propertyName">(optional) The name of the property that changed.</param>
411411
/// <returns><see langword="true"/> if the property was changed, <see langword="false"/> otherwise.</returns>
412-
private bool SetPropertyAndNotifyOnCompletion<TTask>(ITaskNotifier<TTask> taskNotifier, TTask? newValue, global::System.Action<TTask?> callback, [global::System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
412+
private bool SetPropertyAndNotifyOnCompletion<TTask>(ITaskNotifier<TTask> taskNotifier, TTask? newValue, global::System.Action<TTask?>? callback, [global::System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
413413
where TTask : global::System.Threading.Tasks.Task
414414
{
415415
if (ReferenceEquals(taskNotifier.Task, newValue))
@@ -427,7 +427,10 @@ private bool SetPropertyAndNotifyOnCompletion<TTask>(ITaskNotifier<TTask> taskNo
427427

428428
if (isAlreadyCompletedOrNull)
429429
{
430-
callback(newValue);
430+
if (callback != null)
431+
{
432+
callback(newValue);
433+
}
431434

432435
return true;
433436
}
@@ -447,7 +450,10 @@ async void MonitorTask()
447450
OnPropertyChanged(propertyName);
448451
}
449452

450-
callback(newValue);
453+
if (callback != null)
454+
{
455+
callback(newValue);
456+
}
451457
}
452458

453459
MonitorTask();

CommunityToolkit.Mvvm.SourceGenerators/EmbeddedResources/ObservableRecipient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ protected virtual void OnDeactivated()
103103
/// </remarks>
104104
protected virtual void Broadcast<T>(T oldValue, T newValue, string? propertyName)
105105
{
106-
global::CommunityToolkit.Mvvm.Messaging.Messages.PropertyChangedMessage<T> message = new(this, propertyName, oldValue, newValue);
106+
var message = new global::CommunityToolkit.Mvvm.Messaging.Messages.PropertyChangedMessage<T>(this, propertyName, oldValue, newValue);
107107

108108
_ = global::CommunityToolkit.Mvvm.Messaging.IMessengerExtensions.Send(Messenger, message);
109109
}

CommunityToolkit.Mvvm.SourceGenerators/Input/ICommandGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
2929
// Validate the language version
3030
IncrementalValueProvider<bool> isGeneratorSupported =
3131
context.ParseOptionsProvider
32-
.Select(static (item, _) => item is CSharpParseOptions { LanguageVersion: >= LanguageVersion.CSharp9 });
32+
.Select(static (item, _) => item is CSharpParseOptions { LanguageVersion: >= LanguageVersion.CSharp8 });
3333

3434
// Emit the diagnostic, if needed
3535
context.ReportDiagnosticsIsNotSupported(isGeneratorSupported, Diagnostic.Create(UnsupportedCSharpLanguageVersionError, null));

0 commit comments

Comments
 (0)