Browse Source

Enable nullable annotations for Volo.Abp.AspNetCore.Mvc.UI

pull/17094/head
liangshiwei 3 years ago
parent
commit
841f4f17a9
  1. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj
  2. 10
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Alerts/AlertList.cs
  3. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Alerts/AlertMessage.cs
  4. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/BreadCrumb.cs
  5. 6
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/BreadCrumbItem.cs
  6. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Layout/ContentLayout.cs
  7. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/AbpPage.cs
  8. 18
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/AbpPageModel.cs
  9. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/RazorPages/ServiceBasedPageModelActivatorProvider.cs
  10. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/AbpThemingOptions.cs
  11. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/AspNetCore/Mvc/UI/Theming/DefaultThemeManager.cs
  12. 8
      framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo/Abp/ObjectExtending/MvcUiObjectExtensionPropertyInfoExtensions.cs

2
framework/src/Volo.Abp.AspNetCore.Mvc.UI/Volo.Abp.AspNetCore.Mvc.UI.csproj

@ -5,6 +5,8 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<AssemblyName>Volo.Abp.AspNetCore.Mvc.UI</AssemblyName>
<PackageId>Volo.Abp.AspNetCore.Mvc.UI</PackageId>

10
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<AlertMessage>
{
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));
}

8
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));

2
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<BreadCrumbItem>();
}
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));
}

6
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;

4
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()
{

2
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!;
}

18
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<IClock>();
@ -36,7 +36,7 @@ public abstract class AbpPageModel : PageModel
protected IUnitOfWorkManager UnitOfWorkManager => LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>();
protected Type ObjectMapperContext { get; set; }
protected Type? ObjectMapperContext { get; set; }
protected IObjectMapper ObjectMapper => LazyServiceProvider.LazyGetService<IObjectMapper>(provider =>
ObjectMapperContext == null
? provider.GetRequiredService<IObjectMapper>()
@ -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<ICurrentUser>();
@ -75,9 +75,9 @@ public abstract class AbpPageModel : PageModel
protected IAlertManager AlertManager => LazyServiceProvider.LazyGetRequiredService<IAlertManager>();
protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current;
protected IUnitOfWork? CurrentUnitOfWork => UnitOfWorkManager?.Current;
protected ILogger Logger => LazyServiceProvider.LazyGetService<ILogger>(provider => LoggerFactory?.CreateLogger(GetType().FullName) ?? NullLogger.Instance);
protected ILogger Logger => LazyServiceProvider.LazyGetService<ILogger>(provider => LoggerFactory?.CreateLogger(GetType().FullName!) ?? NullLogger.Instance);
protected IAppUrlProvider AppUrlProvider => LazyServiceProvider.LazyGetRequiredService<IAppUrlProvider>();
@ -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);

4
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<PageContext, object> 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<PageContext, object> CreateReleaser([NotNull] CompiledPageActionDescriptor descriptor)
public Action<PageContext, object>? CreateReleaser([NotNull] CompiledPageActionDescriptor descriptor)
{
return null;
}

2
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()
{

2
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)
{

8
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))
{

Loading…
Cancel
Save