Skip to content

Commit

Permalink
修复所有引入的可空
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Mar 3, 2022
1 parent 8faefd8 commit 8e05644
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#nullable enable
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -182,13 +181,13 @@ IEnumerable<StartupTaskWrapper> EnumerateCreate()
/// 例如,你需要根据不同的启动条件决定不同的启动顺序,那么你可能需要使用此方法动态生成关键节点。
/// </para>
/// </remarks>
public StartupManagerBase AddCriticalNodes(string nodeName, string beforeTasks = null, string afterTasks = null)
public StartupManagerBase AddCriticalNodes(string nodeName, string? beforeTasks = null, string? afterTasks = null)
{
var wrapper = GetStartupTaskWrapper(nodeName);
wrapper.TaskBase = new NullObjectStartup();
wrapper.Categories = StartupCategory.All;

if (beforeTasks?.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries) is string[] before)
if (beforeTasks?.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries) is { } before)
{
foreach (var b in before)
{
Expand All @@ -197,7 +196,7 @@ public StartupManagerBase AddCriticalNodes(string nodeName, string beforeTasks =
}
}

if (afterTasks?.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries) is string[] after)
if (afterTasks?.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries) is { } after)
{
foreach (var a in after)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,40 @@ public sealed class StartupTaskAttribute : Attribute
/// <summary>
/// 此启动任务的任务必须在指定的其他启动任务之前完成。可以使用 “;” 分隔符指定多个启动任务。
/// </summary>
public string BeforeTasks { get; set; }
public string? BeforeTasks { get; set; }

/// <summary>
/// 效果上等同于 <see cref="BeforeTasks"/> 属性,此属性只是为了开发方便而已
/// </summary>
public string[] BeforeTaskList
public string[]? BeforeTaskList
{
set
{
BeforeTasks = StartupTaskHelper.BuildTasks(value);
}
get
{
return BeforeTasks.Split(';');
return BeforeTasks?.Split(';');
}
}

/// <summary>
/// 此启动任务的任务将在指定的其他启动任务之后开始执行。可以使用 “;” 分隔符指定多个启动任务。
/// </summary>
public string AfterTasks { get; set; }
public string? AfterTasks { get; set; }

/// <summary>
/// 效果上等同于 <see cref="AfterTasks"/> 属性,此属性只是为了开发方便而已
/// </summary>
public string[] AfterTaskList
public string[]? AfterTaskList
{
set
{
AfterTasks = StartupTaskHelper.BuildTasks(value);
}
get
{
return AfterTasks.Split(';');
return AfterTasks?.Split(';');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,20 @@ protected virtual Task RunAsync(IStartupContext context)
protected internal static Task CompletedTask =>
#if NETFRAMEWORK
CompletedCommonTask;
#pragma warning disable IDE0032 // Use auto property
private static readonly Task CompletedCommonTask = Task.FromResult(true);
#pragma warning restore IDE0032 // Use auto property
#else
Task.CompletedTask;
#endif

public Task TaskResult => CompletedSource.Task;

private TaskCompletionSource<object> CompletedSource { get; } = new TaskCompletionSource<object>();
private TaskCompletionSource<object?> CompletedSource { get; } = new TaskCompletionSource<object?>();

internal IStartupManager Manager { get; set; }
// 框架注入,一定不为空
= null!;

protected TValue FetchValue<TStartup, TValue>() where TStartup : StartupTaskBase, IStartupValueProvider<TValue>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
{
static class StartupTaskHelper
{
public static string BuildTasks(params string[] taskList)
public static string? BuildTasks(params string[]? taskList)
{
if (taskList is null)
{
return null;
}

if (taskList.Length > 1)
{
return string.Join(";", taskList);
Expand Down
16 changes: 3 additions & 13 deletions src/dotnetCampus.ApplicationStartupManager/StartupTaskMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace dotnetCampus.ApplicationStartupManager
public class StartupTaskMetadata
{
private readonly Lazy<StartupTaskBase> _taskLazy;
private string _afterTasks;
private string _beforeTasks;

/// <summary>
/// 创建 <see cref="StartupTaskMetadata"/> 的新实例。
Expand All @@ -31,27 +29,19 @@ public StartupTaskMetadata( string key, Func<StartupTaskBase> creator)
public string Key { get; }

/// <summary>
/// 获取<see cref="StartupTaskAttribute.Categories"/> 的值
/// 获取 Categories 的值
/// </summary>
public StartupCategory Categories { get; set; } = StartupCategory.All;

/// <summary>
/// 获取 <see cref="StartupTaskAttribute.BeforeTasks"/> 的值,如果没有标记,则为 null。
/// </summary>
public string BeforeTasks
{
get => _beforeTasks;
set => _beforeTasks = value;
}
public string? BeforeTasks { get; set; }

/// <summary>
/// 获取 <see cref="StartupTaskAttribute.AfterTasks"/> 的值,如果没有标记,则为 null。
/// </summary>
public string AfterTasks
{
get => _afterTasks;
set => _afterTasks = value;
}
public string? AfterTasks { get; set; }

/// <summary>
/// 获取 <see cref="StartupTaskAttribute.Scheduler"/> 的值,如果没有标记,则为 <see cref="StartupScheduler.Default"/>。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ internal class StartupTaskWrapper : IStartupTaskWrapper

public StartupCategory Categories { get; internal set; } = StartupCategory.All;

public StartupTaskBase TaskBase { get; internal set; }
public StartupTaskBase TaskBase { get; internal set; }
// 框架注入,一定不为空
= null!;
public bool UIOnly { get; internal set; }
public StartupCriticalLevel CriticalLevel { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

<!-- <GenerateDocumentationFile>true</GenerateDocumentationFile> -->
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
Expand Down Expand Up @@ -42,7 +43,7 @@

<ItemGroup>
<!--<PackageReference Include="dotnetCampus.Configurations" Version="1.6.9" />-->
<PackageReference Include="dotnetCampus.SourceYard" Version="0.1.19369-alpha">
<PackageReference Include="dotnetCampus.SourceYard" Version="1.0.0-alpha01">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down

0 comments on commit 8e05644

Please sign in to comment.