null checks

This commit is contained in:
Schedel Pascal
2024-06-17 08:27:18 +02:00
parent c453434c58
commit d3b935bebc

View File

@@ -2,13 +2,14 @@
using OwnChar.Manager.Exceptions;
using OwnChar.Model;
using Pilz.Cryptography;
using System.Diagnostics.CodeAnalysis;
namespace OwnChar.Manager;
public class OwnCharManager
{
// User
public bool IsLoggedIn => CurrentUser != null;
public bool IsLoggedIn => CurrentUser != null && DataManager != null;
public UserAccount? CurrentUser { get; private set; }
// Data Provider
@@ -26,6 +27,7 @@ public class OwnCharManager
Characters = new(this);
}
[MemberNotNull(nameof(CurrentUser), nameof(DataManager))]
internal protected void CheckLogin()
{
if (!IsLoggedIn)
@@ -36,6 +38,7 @@ public class OwnCharManager
/// Tries to login on the given data provider.
/// </summary>
/// <returns>Returns <see cref="true"/> if the login was successfull and <see cref="false"/> if not.</returns>
[MemberNotNullWhen(true, nameof(CurrentUser), nameof(DataManager))]
public bool Login(IDataManager? proxy, string? username, SecureString? password)
{
ArgumentNullException.ThrowIfNull(proxy, nameof(proxy));