Browse Source

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

pull/17094/head
liangshiwei 3 years ago
parent
commit
7dbcf34be5
  1. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo.Abp.AspNetCore.Mvc.UI.Widgets.csproj
  2. 6
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/AbpViewComponentHelper.cs
  3. 3
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/Components/WidgetResourcesViewModel.cs
  4. 23
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetAttribute.cs
  5. 17
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs
  6. 13
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinitionCollection.cs
  7. 4
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetManager.cs
  8. 6
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetResourceItem.cs

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

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

6
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/AbpViewComponentHelper.cs

@ -28,7 +28,7 @@ public class AbpViewComponentHelper : IViewComponentHelper, IViewContextAware, I
Options = widgetOptions.Value; Options = widgetOptions.Value;
} }
public virtual async Task<IHtmlContent> InvokeAsync(string name, object arguments) public virtual async Task<IHtmlContent> InvokeAsync(string name, object? arguments)
{ {
var widget = Options.Widgets.Find(name); var widget = Options.Widgets.Find(name);
if (widget == null) if (widget == null)
@ -39,7 +39,7 @@ public class AbpViewComponentHelper : IViewComponentHelper, IViewContextAware, I
return await InvokeWidgetAsync(arguments, widget); return await InvokeWidgetAsync(arguments, widget);
} }
public virtual async Task<IHtmlContent> InvokeAsync(Type componentType, object arguments) public virtual async Task<IHtmlContent> InvokeAsync(Type componentType, object? arguments)
{ {
var widget = Options.Widgets.Find(componentType); var widget = Options.Widgets.Find(componentType);
if (widget == null) if (widget == null)
@ -55,7 +55,7 @@ public class AbpViewComponentHelper : IViewComponentHelper, IViewContextAware, I
DefaultViewComponentHelper.Contextualize(viewContext); DefaultViewComponentHelper.Contextualize(viewContext);
} }
protected virtual async Task<IHtmlContent> InvokeWidgetAsync(object arguments, WidgetDefinition widget) protected virtual async Task<IHtmlContent> InvokeWidgetAsync(object? arguments, WidgetDefinition widget)
{ {
PageWidgetManager.TryAdd(widget); PageWidgetManager.TryAdd(widget);

3
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/Components/WidgetResourcesViewModel.cs

@ -4,5 +4,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets.Components;
public class WidgetResourcesViewModel public class WidgetResourcesViewModel
{ {
public IReadOnlyList<WidgetDefinition> Widgets { get; set; } public IReadOnlyList<WidgetDefinition> Widgets { get; set; } = default!;
} }

23
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetAttribute.cs

@ -8,30 +8,23 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets;
[AttributeUsage(AttributeTargets.Class)] [AttributeUsage(AttributeTargets.Class)]
public class WidgetAttribute : Attribute public class WidgetAttribute : Attribute
{ {
[CanBeNull] public string[]? StyleFiles { get; set; }
public string[] StyleFiles { get; set; }
[CanBeNull] public Type[]? StyleTypes { get; set; }
public Type[] StyleTypes { get; set; }
[CanBeNull] public string[]? ScriptFiles { get; set; }
public string[] ScriptFiles { get; set; }
[CanBeNull] public Type[]? ScriptTypes { get; set; }
public Type[] ScriptTypes { get; set; }
[CanBeNull] public string? DisplayName { get; set; }
public string DisplayName { get; set; }
[CanBeNull] public Type? DisplayNameResource { get; set; }
public Type DisplayNameResource { get; set; }
[CanBeNull] public string[]? RequiredPolicies { get; set; }
public string[] RequiredPolicies { get; set; }
public bool RequiresAuthentication { get; set; } public bool RequiresAuthentication { get; set; }
public string RefreshUrl { get; set; } public string? RefreshUrl { get; set; }
public bool AutoInitialize { get; set; } public bool AutoInitialize { get; set; }

17
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinition.cs

@ -26,7 +26,7 @@ public class WidgetDefinition
get => _displayName; get => _displayName;
set => _displayName = Check.NotNull(value, nameof(value)); set => _displayName = Check.NotNull(value, nameof(value));
} }
private ILocalizableString _displayName; private ILocalizableString _displayName = default!;
[NotNull] [NotNull]
public Type ViewComponentType { get; } public Type ViewComponentType { get; }
@ -46,14 +46,13 @@ public class WidgetDefinition
[NotNull] [NotNull]
public List<WidgetResourceItem> Scripts { get; } public List<WidgetResourceItem> Scripts { get; }
[CanBeNull] public string? RefreshUrl { get; set; }
public string RefreshUrl { get; set; }
public bool AutoInitialize { get; set; } public bool AutoInitialize { get; set; }
public WidgetDefinition( public WidgetDefinition(
[NotNull] Type viewComponentType, [NotNull] Type viewComponentType,
[CanBeNull] ILocalizableString displayName = null) ILocalizableString? displayName = null)
{ {
ViewComponentType = Check.NotNull(viewComponentType, nameof(viewComponentType)); ViewComponentType = Check.NotNull(viewComponentType, nameof(viewComponentType));
@ -74,12 +73,12 @@ public class WidgetDefinition
if (!widgetAttribute.StyleTypes.IsNullOrEmpty()) if (!widgetAttribute.StyleTypes.IsNullOrEmpty())
{ {
styles.AddRange(widgetAttribute.StyleTypes.Select(type => new WidgetResourceItem(type))); styles.AddRange(widgetAttribute.StyleTypes!.Select(type => new WidgetResourceItem(type)));
} }
if (!widgetAttribute.StyleFiles.IsNullOrEmpty()) if (!widgetAttribute.StyleFiles.IsNullOrEmpty())
{ {
styles.AddRange(widgetAttribute.StyleFiles.Select(src => new WidgetResourceItem(src))); styles.AddRange(widgetAttribute.StyleFiles!.Select(src => new WidgetResourceItem(src)));
} }
return styles; return styles;
@ -91,12 +90,12 @@ public class WidgetDefinition
if (!widgetAttribute.ScriptTypes.IsNullOrEmpty()) if (!widgetAttribute.ScriptTypes.IsNullOrEmpty())
{ {
scripts.AddRange(widgetAttribute.ScriptTypes.Select(type => new WidgetResourceItem(type))); scripts.AddRange(widgetAttribute.ScriptTypes!.Select(type => new WidgetResourceItem(type)));
} }
if (!widgetAttribute.ScriptFiles.IsNullOrEmpty()) if (!widgetAttribute.ScriptFiles.IsNullOrEmpty())
{ {
scripts.AddRange(widgetAttribute.ScriptFiles.Select(src => new WidgetResourceItem(src))); scripts.AddRange(widgetAttribute.ScriptFiles!.Select(src => new WidgetResourceItem(src)));
} }
return scripts; return scripts;
@ -108,7 +107,7 @@ public class WidgetDefinition
if (!widgetAttribute.RequiredPolicies.IsNullOrEmpty()) if (!widgetAttribute.RequiredPolicies.IsNullOrEmpty())
{ {
policies.AddRange(widgetAttribute.RequiredPolicies); policies.AddRange(widgetAttribute.RequiredPolicies!);
} }
return policies; return policies;

13
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetDefinitionCollection.cs

@ -30,34 +30,31 @@ public class WidgetDefinitionCollection
} }
public WidgetDefinition Add<TViewComponent>( public WidgetDefinition Add<TViewComponent>(
[CanBeNull] ILocalizableString displayName = null) ILocalizableString? displayName = null)
{ {
return Add(typeof(TViewComponent), displayName); return Add(typeof(TViewComponent), displayName);
} }
public WidgetDefinition Add( public WidgetDefinition Add(
[NotNull] Type viewComponentType, [NotNull] Type viewComponentType,
[CanBeNull] ILocalizableString displayName = null) ILocalizableString? displayName = null)
{ {
var widget = new WidgetDefinition(viewComponentType, displayName); var widget = new WidgetDefinition(viewComponentType, displayName);
Add(widget); Add(widget);
return widget; return widget;
} }
[CanBeNull] public WidgetDefinition? Find(string name)
public WidgetDefinition Find(string name)
{ {
return _widgetsByName.GetOrDefault(name); return _widgetsByName.GetOrDefault(name);
} }
[CanBeNull] public WidgetDefinition? Find<TViewComponent>()
public WidgetDefinition Find<TViewComponent>()
{ {
return Find(typeof(TViewComponent)); return Find(typeof(TViewComponent));
} }
[CanBeNull] public WidgetDefinition? Find(Type viewComponentType)
public WidgetDefinition Find(Type viewComponentType)
{ {
return _widgetsByType.GetOrDefault(viewComponentType); return _widgetsByType.GetOrDefault(viewComponentType);
} }

4
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetManager.cs

@ -27,7 +27,7 @@ public class WidgetManager : IWidgetManager
{ {
var widget = Options.Widgets.Find(widgetComponentType); var widget = Options.Widgets.Find(widgetComponentType);
return await IsGrantedAsyncInternal(widget, widgetComponentType.FullName); return await IsGrantedAsyncInternal(widget, widgetComponentType.FullName!);
} }
public async Task<bool> IsGrantedAsync(string name) public async Task<bool> IsGrantedAsync(string name)
@ -37,7 +37,7 @@ public class WidgetManager : IWidgetManager
return await IsGrantedAsyncInternal(widget, name); return await IsGrantedAsyncInternal(widget, name);
} }
private async Task<bool> IsGrantedAsyncInternal(WidgetDefinition widget, string wantedWidgetName) private async Task<bool> IsGrantedAsyncInternal(WidgetDefinition? widget, string wantedWidgetName)
{ {
if (widget == null) if (widget == null)
{ {

6
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Widgets/Volo/Abp/AspNetCore/Mvc/UI/Widgets/WidgetResourceItem.cs

@ -5,11 +5,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Widgets;
public class WidgetResourceItem public class WidgetResourceItem
{ {
[CanBeNull] public string? Src { get; }
public string Src { get; }
[CanBeNull] public Type? Type { get; }
public Type Type { get; }
public WidgetResourceItem([NotNull] string src) public WidgetResourceItem([NotNull] string src)
{ {

Loading…
Cancel
Save