Core - Nullable refactoring

Core - Nullable refactoring


Core - Nullable refactoring (finish)
This commit is contained in:
SpoinkyNL committed 2020-11-17 22:50:38 +01:00
1 parent b185b28645
commit fb3466e102
61 files changed
+320 -272

No files matched your search

@@ -16,7 +16,7 @@ namespace Artemis.Core.Modules
/// </summary>
/// <param name="processName">The name of the process that must run</param>
/// <param name="location">The location of where the process must be running from (optional)</param>
public ProcessActivationRequirement(string processName, string location = null)
public ProcessActivationRequirement(string? processName, string? location = null)
{
ProcessName = processName;
Location = location;
@@ -25,12 +25,12 @@ namespace Artemis.Core.Modules
/// <summary>
/// The name of the process that must run
/// </summary>
public string ProcessName { get; set; }
public string? ProcessName { get; set; }
/// <summary>
/// The location of where the process must be running from
/// </summary>
public string Location { get; set; }
public string? Location { get; set; }
/// <inheritdoc />
public bool Evaluate()
+1 -7
View File
@@ -18,7 +18,7 @@ namespace Artemis.Core.Modules
/// </summary>
public T DataModel
{
get => (T) InternalDataModel;
get => InternalDataModel as T ?? throw new InvalidOperationException("Internal datamodel does not match the type of the data model");
internal set => InternalDataModel = value;
}
@@ -52,12 +52,6 @@ namespace Artemis.Core.Modules
DataModel.DataModelDescription = GetDataModelDescription();
base.InternalEnable();
}
internal override void InternalDisable()
{
DataModel = null;
base.InternalDisable();
}
}
@@ -6,12 +6,11 @@ namespace Artemis.Core.Modules
public class ModuleTab<T> : ModuleTab where T : IModuleViewModel
{
/// <summary>
/// Initializes a new instance of the <see cref="ModuleTab{T}" /> class
/// Creates a new instance of the <see cref="ModuleTab{T}" /> class
/// </summary>
/// <param name="title">The title of the tab</param>
public ModuleTab(string title)
public ModuleTab(string title) : base(title)
{
Title = title;
}
/// <inheritdoc />
@@ -24,9 +23,13 @@ namespace Artemis.Core.Modules
public abstract class ModuleTab
{
/// <summary>
/// The module this tab belongs to
/// Creates a new instance of the <see cref="ModuleTab" /> class
/// </summary>
internal Module Module { get; set; }
/// <param name="title">The title of the tab</param>
protected ModuleTab(string title)
{
Title = title;
}
/// <summary>
/// The title of the tab
@@ -22,7 +22,7 @@ namespace Artemis.Core.Modules
/// </summary>
public T DataModel
{
get => (T) InternalDataModel;
get => InternalDataModel as T ?? throw new InvalidOperationException("Internal datamodel does not match the type of the data model");
internal set => InternalDataModel = value;
}
@@ -83,7 +83,6 @@ namespace Artemis.Core.Modules
{
Deactivate(true);
base.InternalDisable();
DataModel = null;
}
}
@@ -182,7 +181,7 @@ namespace Artemis.Core.Modules
ProfileRendered(deltaTime, surface, canvas, canvasInfo);
}
internal async Task ChangeActiveProfileAnimated(Profile profile, ArtemisSurface surface)
internal async Task ChangeActiveProfileAnimated(Profile? profile, ArtemisSurface? surface)
{
if (profile != null && profile.Module != this)
throw new ArtemisCoreException($"Cannot activate a profile of module {profile.Module} on a module of plugin {this}.");
@@ -204,12 +203,14 @@ namespace Artemis.Core.Modules
await Task.Delay(50);
}
internal void ChangeActiveProfile(Profile profile, ArtemisSurface surface)
internal void ChangeActiveProfile(Profile? profile, ArtemisSurface? surface)
{
if (profile != null && profile.Module != this)
throw new ArtemisCoreException($"Cannot activate a profile of module {profile.Module} on a module of plugin {this}.");
if (!IsActivated)
throw new ArtemisCoreException("Cannot activate a profile on a deactivated module");
if (profile != null && surface == null)
throw new ArtemisCoreException("If changing the active profile to a non-null profile, a surface is required");
lock (_lock)
{
@@ -219,7 +220,7 @@ namespace Artemis.Core.Modules
ActiveProfile?.Dispose();
ActiveProfile = profile;
ActiveProfile?.Activate(surface);
ActiveProfile?.Activate(surface!);
}
OnActiveProfileChanged();
@@ -229,7 +230,7 @@ namespace Artemis.Core.Modules
{
base.Deactivate(isOverride);
Profile profile = ActiveProfile;
Profile? profile = ActiveProfile;
ActiveProfile = null;
profile?.Dispose();
}
@@ -249,7 +250,7 @@ namespace Artemis.Core.Modules
/// <summary>
/// Occurs when the <see cref="ActiveProfile" /> has changed
/// </summary>
public event EventHandler ActiveProfileChanged;
public event EventHandler? ActiveProfileChanged;
/// <summary>
/// Invokes the <see cref="ActiveProfileChanged" /> event