Skip to content

Commit

Permalink
Csla.State namespace nullable aware
Browse files Browse the repository at this point in the history
Fixes #1233
  • Loading branch information
StefanOssendorf committed Oct 23, 2024
1 parent a042511 commit 6c84c52
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Source/Csla.AspNetCore/Blazor/State/StateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public virtual StateResult Get(long lastTouched)
}
else
{
var message = (SessionMessage)applicationContext.CreateInstanceDI(typeof(SessionMessage));
message.Session = session;
var message = applicationContext.CreateInstanceDI< SessionMessage>(session);
if (FlowUserIdentityToWebAssembly)
{
message.Principal = applicationContext.Principal;
Expand Down
10 changes: 8 additions & 2 deletions Source/Csla/State/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ public class Session : MobileDictionary<string, object?>, INotifyPropertyChanged
/// Raise PropertyChanged event.
/// </summary>
/// <param name="propertyName"></param>
protected virtual void OnPropertyChanged(string propertyName)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
/// <exception cref="ArgumentNullException"><paramref name="propertyName"/> is <see langword="null"/>.</exception>
protected virtual void OnPropertyChanged(string propertyName)
{
if (propertyName is null)
throw new ArgumentNullException(nameof(propertyName));

PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
29 changes: 24 additions & 5 deletions Source/Csla/State/SessionMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//-----------------------------------------------------------------------

using System.Security.Claims;
using Csla.Serialization.Mobile;

namespace Csla.State;

Expand All @@ -25,20 +26,38 @@ public class SessionMessage : CommandBase<SessionMessage>
/// </summary>
public Session Session
{
get => ReadProperty(SessionProperty);
set => LoadProperty(SessionProperty, value);
get => ReadProperty(SessionProperty)!;
set => LoadProperty(SessionProperty, value ?? throw new ArgumentNullException(nameof(Session)));
}

/// <summary>
/// User principal data
/// </summary>
public static readonly PropertyInfo<ClaimsPrincipal> PrincipalProperty = RegisterProperty<ClaimsPrincipal>(nameof(Principal));
public static readonly PropertyInfo<ClaimsPrincipal?> PrincipalProperty = RegisterProperty<ClaimsPrincipal?>(nameof(Principal));
/// <summary>
/// User principal data
/// </summary>
public ClaimsPrincipal Principal
public ClaimsPrincipal? Principal
{
get => ReadProperty(PrincipalProperty);
set => LoadProperty(PrincipalProperty, value);
}
}

/// <summary>
/// Initializes a new instance of <see cref="SessionMessage"/>.
/// </summary>
/// <param name="session"></param>
/// <exception cref="ArgumentNullException"><paramref name="session"/> is <see langword="null"/>.</exception>
public SessionMessage(Session session)
{
Session = session ?? throw new ArgumentNullException(nameof(session));
}

/// <summary>
/// Initializes a new instance of <see cref="SessionMessage"/>.
/// </summary>
[Obsolete(MobileFormatter.DefaultCtorObsoleteMessage, error: true)]
public SessionMessage()
{
}
}
2 changes: 1 addition & 1 deletion Source/Csla/State/StateResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public class StateResult
/// <summary>
/// Gets or sets the serialized session data.
/// </summary>
public byte[] SessionData { get; set; }
public byte[]? SessionData { get; set; }
}
}

0 comments on commit 6c84c52

Please sign in to comment.