Browse Source

Enable nullable annotations for Volo.Abp.UI.Navigation

pull/17020/head
liangshiwei 3 years ago
parent
commit
cee5f22bb8
  1. 2
      framework/src/Volo.Abp.UI.Navigation/Volo.Abp.UI.Navigation.csproj
  2. 4
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenu.cs
  3. 6
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuExtensions.cs
  4. 12
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuGroup.cs
  5. 38
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuItem.cs
  6. 3
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/HasMenuItemsExtensions.cs
  7. 3
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuConfigurationContext.cs
  8. 2
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs
  9. 14
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs
  10. 2
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/ApplicationUrlInfo.cs
  11. 4
      framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/IAppUrlProvider.cs

2
framework/src/Volo.Abp.UI.Navigation/Volo.Abp.UI.Navigation.csproj

@ -5,6 +5,8 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks> <TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.UI.Navigation</AssemblyName> <AssemblyName>Volo.Abp.UI.Navigation</AssemblyName>
<PackageId>Volo.Abp.UI.Navigation</PackageId> <PackageId>Volo.Abp.UI.Navigation</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> <AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

4
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenu.cs

@ -26,7 +26,7 @@ public class ApplicationMenu : IHasMenuItems, IHasMenuGroups
_displayName = value; _displayName = value;
} }
} }
private string _displayName; private string _displayName = default!;
/// <inheritdoc cref="IHasMenuItems.Items"/> /// <inheritdoc cref="IHasMenuItems.Items"/>
[NotNull] [NotNull]
@ -44,7 +44,7 @@ public class ApplicationMenu : IHasMenuItems, IHasMenuGroups
public ApplicationMenu( public ApplicationMenu(
[NotNull] string name, [NotNull] string name,
string displayName = null) string? displayName = null)
{ {
Check.NotNullOrWhiteSpace(name, nameof(name)); Check.NotNullOrWhiteSpace(name, nameof(name));

6
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuExtensions.cs

@ -29,8 +29,7 @@ public static class ApplicationMenuExtensions
return menuItem; return menuItem;
} }
[CanBeNull] public static ApplicationMenuItem? GetMenuItemOrNull(
public static ApplicationMenuItem GetMenuItemOrNull(
[NotNull] this IHasMenuItems menuWithItems, [NotNull] this IHasMenuItems menuWithItems,
string menuItemName) string menuItemName)
{ {
@ -79,8 +78,7 @@ public static class ApplicationMenuExtensions
return menuGroup; return menuGroup;
} }
[CanBeNull] public static ApplicationMenuGroup? GetMenuGroupOrNull(
public static ApplicationMenuGroup GetMenuGroupOrNull(
[NotNull] this IHasMenuGroups menuWithGroups, [NotNull] this IHasMenuGroups menuWithGroups,
string menuGroupName) string menuGroupName)
{ {

12
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuGroup.cs

@ -4,8 +4,8 @@ namespace Volo.Abp.UI.Navigation;
public class ApplicationMenuGroup public class ApplicationMenuGroup
{ {
private string _displayName; private string _displayName = default!;
private string _elementId; private string? _elementId;
/// <summary> /// <summary>
/// Default <see cref="Order"/> value of a group item. /// Default <see cref="Order"/> value of a group item.
@ -33,7 +33,7 @@ public class ApplicationMenuGroup
/// <summary> /// <summary>
/// Can be used to render the element with a specific Id for DOM selections. /// Can be used to render the element with a specific Id for DOM selections.
/// </summary> /// </summary>
public string ElementId { public string? ElementId {
get { return _elementId; } get { return _elementId; }
set { set {
_elementId = NormalizeElementId(value); _elementId = NormalizeElementId(value);
@ -49,7 +49,7 @@ public class ApplicationMenuGroup
public ApplicationMenuGroup( public ApplicationMenuGroup(
[NotNull] string name, [NotNull] string name,
[NotNull] string displayName, [NotNull] string displayName,
string elementId = null, string? elementId = null,
int order = DefaultOrder) int order = DefaultOrder)
{ {
Check.NotNullOrWhiteSpace(name, nameof(name)); Check.NotNullOrWhiteSpace(name, nameof(name));
@ -57,7 +57,7 @@ public class ApplicationMenuGroup
Name = name; Name = name;
DisplayName = displayName; DisplayName = displayName;
ElementId = elementId; ElementId = elementId ?? GetDefaultElementId();
Order = order; Order = order;
} }
@ -66,7 +66,7 @@ public class ApplicationMenuGroup
return "MenuGroup_" + Name; return "MenuGroup_" + Name;
} }
private string NormalizeElementId(string elementId) private string? NormalizeElementId(string? elementId)
{ {
return elementId?.Replace(".", "_"); return elementId?.Replace(".", "_");
} }

38
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/ApplicationMenuItem.cs

@ -7,8 +7,8 @@ namespace Volo.Abp.UI.Navigation;
public class ApplicationMenuItem : IHasMenuItems, IHasSimpleStateCheckers<ApplicationMenuItem> public class ApplicationMenuItem : IHasMenuItems, IHasSimpleStateCheckers<ApplicationMenuItem>
{ {
private string _displayName; private string _displayName = default!;
private string _elementId; private string? _elementId;
/// <summary> /// <summary>
/// Default <see cref="Order"/> value of a menu item. /// Default <see cref="Order"/> value of a menu item.
@ -42,14 +42,12 @@ public class ApplicationMenuItem : IHasMenuItems, IHasSimpleStateCheckers<Applic
/// <summary> /// <summary>
/// The URL to navigate when this menu item is selected. /// The URL to navigate when this menu item is selected.
/// </summary> /// </summary>
[CanBeNull] public string? Url { get; set; }
public string Url { get; set; }
/// <summary> /// <summary>
/// Icon of the menu item if exists. /// Icon of the menu item if exists.
/// </summary> /// </summary>
[CanBeNull] public string? Icon { get; set; }
public string Icon { get; set; }
/// <summary> /// <summary>
/// Returns true if this menu item has no child <see cref="Items"/>. /// Returns true if this menu item has no child <see cref="Items"/>.
@ -59,8 +57,7 @@ public class ApplicationMenuItem : IHasMenuItems, IHasSimpleStateCheckers<Applic
/// <summary> /// <summary>
/// Target of the menu item. Can be null, "_blank", "_self", "_parent", "_top" or a frame name for web applications. /// Target of the menu item. Can be null, "_blank", "_self", "_parent", "_top" or a frame name for web applications.
/// </summary> /// </summary>
[CanBeNull] public string? Target { get; set; }
public string Target { get; set; }
/// <summary> /// <summary>
/// Can be used to disable this menu item. /// Can be used to disable this menu item.
@ -71,9 +68,8 @@ public class ApplicationMenuItem : IHasMenuItems, IHasSimpleStateCheckers<Applic
[NotNull] [NotNull]
public ApplicationMenuItemList Items { get; } public ApplicationMenuItemList Items { get; }
[CanBeNull]
[Obsolete("Use RequirePermissions extension method.")] [Obsolete("Use RequirePermissions extension method.")]
public string RequiredPermissionName { get; set; } public string? RequiredPermissionName { get; set; }
public List<ISimpleStateChecker<ApplicationMenuItem>> StateCheckers { get; } public List<ISimpleStateChecker<ApplicationMenuItem>> StateCheckers { get; }
@ -86,7 +82,7 @@ public class ApplicationMenuItem : IHasMenuItems, IHasSimpleStateCheckers<Applic
/// <summary> /// <summary>
/// Can be used to render the element with a specific Id for DOM selections. /// Can be used to render the element with a specific Id for DOM selections.
/// </summary> /// </summary>
public string ElementId { public string? ElementId {
get { return _elementId; } get { return _elementId; }
set { set {
_elementId = NormalizeElementId(value); _elementId = NormalizeElementId(value);
@ -96,24 +92,24 @@ public class ApplicationMenuItem : IHasMenuItems, IHasSimpleStateCheckers<Applic
/// <summary> /// <summary>
/// Can be used to render the element with extra CSS classes. /// Can be used to render the element with extra CSS classes.
/// </summary> /// </summary>
public string CssClass { get; set; } public string? CssClass { get; set; }
/// <summary> /// <summary>
/// Can be used to group menu items. /// Can be used to group menu items.
/// </summary> /// </summary>
public string GroupName { get; set; } public string? GroupName { get; set; }
public ApplicationMenuItem( public ApplicationMenuItem(
[NotNull] string name, [NotNull] string name,
[NotNull] string displayName, [NotNull] string displayName,
string url = null, string? url = null,
string icon = null, string? icon = null,
int order = DefaultOrder, int order = DefaultOrder,
string target = null, string? target = null,
string elementId = null, string? elementId = null,
string cssClass = null, string? cssClass = null,
string groupName = null, string? groupName = null,
string requiredPermissionName = null) string? requiredPermissionName = null)
{ {
Check.NotNullOrWhiteSpace(name, nameof(name)); Check.NotNullOrWhiteSpace(name, nameof(name));
Check.NotNullOrWhiteSpace(displayName, nameof(displayName)); Check.NotNullOrWhiteSpace(displayName, nameof(displayName));
@ -158,7 +154,7 @@ public class ApplicationMenuItem : IHasMenuItems, IHasSimpleStateCheckers<Applic
return "MenuItem_" + Name; return "MenuItem_" + Name;
} }
private string NormalizeElementId(string elementId) private string? NormalizeElementId(string? elementId)
{ {
return elementId?.Replace(".", "_"); return elementId?.Replace(".", "_");
} }

3
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/HasMenuItemsExtensions.cs

@ -5,8 +5,7 @@ namespace Volo.Abp.UI.Navigation;
public static class HasMenuItemsExtensions public static class HasMenuItemsExtensions
{ {
[CanBeNull] public static ApplicationMenuItem? FindMenuItem(this IHasMenuItems container, string menuItemName)
public static ApplicationMenuItem FindMenuItem(this IHasMenuItems container, string menuItemName)
{ {
foreach (var menuItem in container.Items) foreach (var menuItem in container.Items)
{ {

3
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuConfigurationContext.cs

@ -32,8 +32,7 @@ public class MenuConfigurationContext : IMenuConfigurationContext
return AuthorizationService.IsGrantedAsync(policyName); return AuthorizationService.IsGrantedAsync(policyName);
} }
[CanBeNull] public IStringLocalizer? GetDefaultLocalizer()
public IStringLocalizer GetDefaultLocalizer()
{ {
return StringLocalizerFactory.CreateDefaultOrNull(); return StringLocalizerFactory.CreateDefaultOrNull();
} }

2
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/MenuManager.cs

@ -165,7 +165,7 @@ public class MenuManager : IMenuManager, ITransientDependency
{ {
foreach (var menuGroup in applicationMenu.Items.Where(x => !x.GroupName.IsNullOrWhiteSpace()).GroupBy(x => x.GroupName)) foreach (var menuGroup in applicationMenu.Items.Where(x => !x.GroupName.IsNullOrWhiteSpace()).GroupBy(x => x.GroupName))
{ {
var group = applicationMenu.GetMenuGroupOrNull(menuGroup.First().GroupName); var group = applicationMenu.GetMenuGroupOrNull(menuGroup.First().GroupName!);
if (group != null) if (group != null)
{ {
continue; continue;

14
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs

@ -33,7 +33,7 @@ public class AppUrlProvider : IAppUrlProvider, ITransientDependency
Logger = NullLogger<AppUrlProvider>.Instance; Logger = NullLogger<AppUrlProvider>.Instance;
} }
public virtual async Task<string> GetUrlAsync(string appName, string urlName = null) public virtual async Task<string> GetUrlAsync(string appName, string? urlName = null)
{ {
return await ReplacePlaceHoldersAsync( return await ReplacePlaceHoldersAsync(
await GetConfiguredUrl( await GetConfiguredUrl(
@ -53,12 +53,12 @@ public class AppUrlProvider : IAppUrlProvider, ITransientDependency
return allow; return allow;
} }
protected virtual async Task<string> GetConfiguredUrl(string appName, string urlName) protected virtual async Task<string> GetConfiguredUrl(string appName, string? urlName)
{ {
var url = await GetUrlOrNullAsync(appName, urlName); var url = await GetUrlOrNullAsync(appName, urlName);
if (!url.IsNullOrEmpty()) if (!url.IsNullOrEmpty())
{ {
return url; return url!;
} }
if (!urlName.IsNullOrEmpty()) if (!urlName.IsNullOrEmpty())
@ -115,10 +115,10 @@ public class AppUrlProvider : IAppUrlProvider, ITransientDependency
return tenantConfiguration.Name; return tenantConfiguration.Name;
} }
return CurrentTenant.Name; return CurrentTenant.Name!;
} }
public Task<string> GetUrlOrNullAsync([NotNull] string appName, [CanBeNull] string urlName = null) public Task<string?> GetUrlOrNullAsync([NotNull] string appName, string? urlName = null)
{ {
var app = Options.Applications[appName]; var app = Options.Applications[appName];
@ -127,13 +127,13 @@ public class AppUrlProvider : IAppUrlProvider, ITransientDependency
return Task.FromResult(app.RootUrl); return Task.FromResult(app.RootUrl);
} }
var url = app.Urls.GetOrDefault(urlName); var url = app.Urls.GetOrDefault(urlName!);
if (app.RootUrl == null) if (app.RootUrl == null)
{ {
return Task.FromResult(url); return Task.FromResult(url);
} }
return Task.FromResult(app.RootUrl.EnsureEndsWith('/') + url); return Task.FromResult<string?>(app.RootUrl.EnsureEndsWith('/') + url);
} }
} }

2
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/ApplicationUrlInfo.cs

@ -4,7 +4,7 @@ namespace Volo.Abp.UI.Navigation.Urls;
public class ApplicationUrlInfo public class ApplicationUrlInfo
{ {
public string RootUrl { get; set; } public string? RootUrl { get; set; }
public IDictionary<string, string> Urls { get; } public IDictionary<string, string> Urls { get; }

4
framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/IAppUrlProvider.cs

@ -5,9 +5,9 @@ namespace Volo.Abp.UI.Navigation.Urls;
public interface IAppUrlProvider public interface IAppUrlProvider
{ {
Task<string> GetUrlAsync([NotNull] string appName, [CanBeNull] string urlName = null); Task<string> GetUrlAsync([NotNull] string appName, string? urlName = null);
Task<string> GetUrlOrNullAsync([NotNull] string appName, [CanBeNull] string urlName = null); Task<string?> GetUrlOrNullAsync([NotNull] string appName, string? urlName = null);
bool IsRedirectAllowedUrl(string url); bool IsRedirectAllowedUrl(string url);
} }

Loading…
Cancel
Save