private void ReplaceDisplay(Display newDisplay)
{
- if (_display != null)
- {
- _display.Owner = null;
- }
+ _display?.SetOwner(null);
_display = newDisplay;
- if (_display != null)
- {
- _display.Owner = this;
- }
+ _display?.SetOwner(this);
}
/// <summary>
{
ValidateState(CameraState.Created);
- if (value != null && value.Owner != null)
+ if (value?.Owner != null)
{
if (ReferenceEquals(this, value.Owner))
{
return;
}
- else
- {
- throw new ArgumentException("The display has already been assigned to another.");
- }
+
+ throw new ArgumentException("The display has already been assigned to another.");
}
+
CameraErrorFactory.ThrowIfError(SetDisplay(value), "Failed to set the camera display");
ReplaceDisplay(value);
private PlayerErrorCode SetDisplay(Display display)
{
- Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
if (display == null)
{
Log.Info(PlayerLog.Tag, "set display to none");
private void ReplaceDisplay(Display newDisplay)
{
- if (_display != null)
- {
- _display.Owner = null;
- }
+ _display?.SetOwner(null);
_display = newDisplay;
- if (_display != null)
- {
- _display.Owner = this;
- }
+ _display?.SetOwner(this);
}
/// <summary>
}
set
{
- Log.Debug(PlayerLog.Tag, PlayerLog.Enter);
ValidatePlayerState(PlayerState.Idle);
- if (value != null && value.Owner != null)
+ if (value?.Owner != null)
{
if (ReferenceEquals(this, value.Owner))
{
return;
}
- else
- {
- throw new ArgumentException("The display has already been assigned to another.");
- }
- }
+ throw new ArgumentException("The display has already been assigned to another.");
+ }
SetDisplay(value).ThrowIfFailed("Failed to set the display to the player");
ReplaceDisplay(value);
- Log.Debug(PlayerLog.Tag, PlayerLog.Leave);
}
}
private DisplayType Type { get; }
- internal object Owner
+ private object _owner;
+
+ internal object Owner => _owner;
+
+ internal void SetOwner(object newOwner)
{
- get;
- set;
+ if (_owner != null && newOwner != null)
+ {
+ throw new ArgumentException("The display has already been assigned to another.");
+ }
+
+ _owner = newOwner;
}
internal ErrorType ApplyTo<ErrorType>(IDisplayable<ErrorType> target)