From 841f4f17a9da3101fb47a1a9eede21903af61a48 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Tue, 11 Jul 2023 16:39:10 +0800 Subject: [PATCH] Enable nullable annotations for Volo.Abp.AspNetCore.Mvc.UI --- .../Volo.Abp.AspNetCore.Mvc.UI.csproj | 2 ++ .../Abp/AspNetCore/Mvc/UI/Alerts/AlertList.cs | 10 +++++----- .../AspNetCore/Mvc/UI/Alerts/AlertMessage.cs | 8 ++++---- .../Abp/AspNetCore/Mvc/UI/Layout/BreadCrumb.cs | 2 +- .../AspNetCore/Mvc/UI/Layout/BreadCrumbItem.cs | 6 +++--- .../AspNetCore/Mvc/UI/Layout/ContentLayout.cs | 4 ++-- .../AspNetCore/Mvc/UI/RazorPages/AbpPage.cs | 2 +- .../Mvc/UI/RazorPages/AbpPageModel.cs | 18 +++++++++--------- .../ServiceBasedPageModelActivatorProvider.cs | 4 ++-- .../Mvc/UI/Theming/AbpThemingOptions.cs | 2 +- .../Mvc/UI/Theming/DefaultThemeManager.cs | 2 +- ...cUiObjectExtensionPropertyInfoExtensions.cs | 8 ++++---- 12 files changed, 35 insertions(+), 33 deletions(-) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj index 1975ba8a67..1d1234a147 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj @@ -5,6 +5,8 @@ net7.0 + enable + Nullable true Volo.Abp.AspNetCore.Mvc.UI Volo.Abp.AspNetCore.Mvc.UI diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Alerts/AlertList.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Alerts/AlertList.cs index 123cdfff33..279a1674a3 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Alerts/AlertList.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Alerts/AlertList.cs @@ -4,27 +4,27 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Alerts; public class AlertList : List { - public void Add(AlertType type, string text, string title = null, bool dismissible = true) + public void Add(AlertType type, string text, string? title = null, bool dismissible = true) { Add(new AlertMessage(type, text, title, dismissible)); } - public void Info(string text, string title = null, bool dismissible = true) + public void Info(string text, string? title = null, bool dismissible = true) { Add(new AlertMessage(AlertType.Info, text, title, dismissible)); } - public void Warning(string text, string title = null, bool dismissible = true) + public void Warning(string text, string? title = null, bool dismissible = true) { Add(new AlertMessage(AlertType.Warning, text, title, dismissible)); } - public void Danger(string text, string title = null, bool dismissible = true) + public void Danger(string text, string? title = null, bool dismissible = true) { Add(new AlertMessage(AlertType.Danger, text, title, dismissible)); } - public void Success(string text, string title = null, bool dismissible = true) + public void Success(string text, string? title = null, bool dismissible = true) { Add(new AlertMessage(AlertType.Success, text, title, dismissible)); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Alerts/AlertMessage.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Alerts/AlertMessage.cs index be725d20c1..42dbaf0086 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Alerts/AlertMessage.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Alerts/AlertMessage.cs @@ -9,16 +9,16 @@ public class AlertMessage get => _text; set => _text = Check.NotNullOrWhiteSpace(value, nameof(value)); } - private string _text; + + private string _text = default!; public AlertType Type { get; set; } - [CanBeNull] - public string Title { get; set; } + public string? Title { get; set; } public bool Dismissible { get; set; } - public AlertMessage(AlertType type, [NotNull] string text, string title = null, bool dismissible = true) + public AlertMessage(AlertType type, [NotNull] string text, string? title = null, bool dismissible = true) { Type = type; Text = Check.NotNullOrWhiteSpace(text, nameof(text)); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/BreadCrumb.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/BreadCrumb.cs index 7bc702662a..da210e7b78 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/BreadCrumb.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/BreadCrumb.cs @@ -21,7 +21,7 @@ public class BreadCrumb Items = new List(); } - public void Add(string text, string url = null, string icon = null) + public void Add(string text, string? url = null, string? icon = null) { Items.Add(new BreadCrumbItem(text, url, icon)); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/BreadCrumbItem.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/BreadCrumbItem.cs index 24b1208175..fd405f82ec 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/BreadCrumbItem.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/BreadCrumbItem.cs @@ -4,11 +4,11 @@ public class BreadCrumbItem { public string Text { get; set; } - public string Icon { get; set; } + public string? Icon { get; set; } - public string Url { get; set; } + public string? Url { get; set; } - public BreadCrumbItem(string text, string url = null, string icon = null) + public BreadCrumbItem(string text, string? url = null, string? icon = null) { Text = text; Url = url; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/ContentLayout.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/ContentLayout.cs index 188853f88d..1e5abce611 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/ContentLayout.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/ContentLayout.cs @@ -5,11 +5,11 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Layout; public class ContentLayout { - public string Title { get; set; } + public string? Title { get; set; } public BreadCrumb BreadCrumb { get; } - public string MenuItemName { get; set; } + public string? MenuItemName { get; set; } public ContentLayout() { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/AbpPage.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/AbpPage.cs index 4a1e6f505c..9028b82171 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/AbpPage.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/AbpPage.cs @@ -7,5 +7,5 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.RazorPages; public abstract class AbpPage : Page { [RazorInject] - public ICurrentUser CurrentUser { get; set; } + public ICurrentUser CurrentUser { get; set; } = default!; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/AbpPageModel.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/AbpPageModel.cs index b2d3d1172b..907e462526 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/AbpPageModel.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/AbpPageModel.cs @@ -25,10 +25,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.RazorPages; public abstract class AbpPageModel : PageModel { - public IAbpLazyServiceProvider LazyServiceProvider { get; set; } + public IAbpLazyServiceProvider LazyServiceProvider { get; set; } = default!; [Obsolete("Use LazyServiceProvider instead.")] - public IServiceProvider ServiceProvider { get; set; } + public IServiceProvider ServiceProvider { get; set; } = default!; protected IClock Clock => LazyServiceProvider.LazyGetRequiredService(); @@ -36,7 +36,7 @@ public abstract class AbpPageModel : PageModel protected IUnitOfWorkManager UnitOfWorkManager => LazyServiceProvider.LazyGetRequiredService(); - protected Type ObjectMapperContext { get; set; } + protected Type? ObjectMapperContext { get; set; } protected IObjectMapper ObjectMapper => LazyServiceProvider.LazyGetService(provider => ObjectMapperContext == null ? provider.GetRequiredService() @@ -59,9 +59,9 @@ public abstract class AbpPageModel : PageModel } } - private IStringLocalizer _localizer; + private IStringLocalizer? _localizer; - protected Type LocalizationResourceType { get; set; } + protected Type? LocalizationResourceType { get; set; } protected ICurrentUser CurrentUser => LazyServiceProvider.LazyGetRequiredService(); @@ -75,9 +75,9 @@ public abstract class AbpPageModel : PageModel protected IAlertManager AlertManager => LazyServiceProvider.LazyGetRequiredService(); - protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current; + protected IUnitOfWork? CurrentUnitOfWork => UnitOfWorkManager?.Current; - protected ILogger Logger => LazyServiceProvider.LazyGetService(provider => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance); + protected ILogger Logger => LazyServiceProvider.LazyGetService(provider => LoggerFactory?.CreateLogger(GetType().FullName!) ?? NullLogger.Instance); protected IAppUrlProvider AppUrlProvider => LazyServiceProvider.LazyGetRequiredService(); @@ -122,12 +122,12 @@ public abstract class AbpPageModel : PageModel return localizer; } - protected RedirectResult RedirectSafely(string returnUrl, string returnUrlHash = null) + protected RedirectResult RedirectSafely(string returnUrl, string? returnUrlHash = null) { return Redirect(GetRedirectUrl(returnUrl, returnUrlHash)); } - protected virtual string GetRedirectUrl(string returnUrl, string returnUrlHash = null) + protected virtual string GetRedirectUrl(string returnUrl, string? returnUrlHash = null) { returnUrl = NormalizeReturnUrl(returnUrl); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/ServiceBasedPageModelActivatorProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/ServiceBasedPageModelActivatorProvider.cs index aa71f09ef8..c85d20373d 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/ServiceBasedPageModelActivatorProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/ServiceBasedPageModelActivatorProvider.cs @@ -12,10 +12,10 @@ public class ServiceBasedPageModelActivatorProvider : IPageModelActivatorProvide public Func CreateActivator([NotNull] CompiledPageActionDescriptor descriptor) { Check.NotNull(descriptor, nameof(descriptor)); - return context => context.HttpContext.RequestServices.GetRequiredService(descriptor.ModelTypeInfo); + return context => context.HttpContext.RequestServices.GetRequiredService(descriptor.ModelTypeInfo!); } - public Action CreateReleaser([NotNull] CompiledPageActionDescriptor descriptor) + public Action? CreateReleaser([NotNull] CompiledPageActionDescriptor descriptor) { return null; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/AbpThemingOptions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/AbpThemingOptions.cs index 6b45008e71..1197ad6e53 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/AbpThemingOptions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/AbpThemingOptions.cs @@ -4,7 +4,7 @@ public class AbpThemingOptions { public ThemeDictionary Themes { get; } - public string DefaultThemeName { get; set; } + public string? DefaultThemeName { get; set; } public AbpThemingOptions() { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/DefaultThemeManager.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/DefaultThemeManager.cs index 658923176f..39e97bc518 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/DefaultThemeManager.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/DefaultThemeManager.cs @@ -27,7 +27,7 @@ public class DefaultThemeManager : IThemeManager, IScopedDependency, IServicePro protected virtual ITheme GetCurrentTheme() { - var preSelectedTheme = HttpContextAccessor.HttpContext.Items[CurrentThemeHttpContextKey] as ITheme; + var preSelectedTheme = HttpContextAccessor.HttpContext!.Items[CurrentThemeHttpContextKey] as ITheme; if (preSelectedTheme == null) { diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs index aa41bcd5a2..d4d1b796ee 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs @@ -35,7 +35,7 @@ public static class MvcUiObjectExtensionPropertyInfoExtensions typeof(decimal?) }; - public static string GetInputFormatOrNull(this IBasicObjectExtensionPropertyInfo property) + public static string? GetInputFormatOrNull(this IBasicObjectExtensionPropertyInfo property) { var formatString = property.GetDataFormatStringOrNull(); @@ -57,7 +57,7 @@ public static class MvcUiObjectExtensionPropertyInfoExtensions return null; } - public static string GetInputValueOrNull(this IBasicObjectExtensionPropertyInfo property, object value) + public static string? GetInputValueOrNull(this IBasicObjectExtensionPropertyInfo property, object? value) { if (value == null) { @@ -88,7 +88,7 @@ public static class MvcUiObjectExtensionPropertyInfoExtensions ?? "text"; //default } - private static string GetInputTypeFromAttributeOrNull(Attribute attribute) + private static string? GetInputTypeFromAttributeOrNull(Attribute attribute) { if (attribute is EmailAddressAttribute) { @@ -134,7 +134,7 @@ public static class MvcUiObjectExtensionPropertyInfoExtensions return null; } - private static string GetInputTypeFromTypeOrNull(Type type) + private static string? GetInputTypeFromTypeOrNull(Type type) { if (type == typeof(bool)) {