Skip to content

Commit

Permalink
refactor: more C#10 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-welker committed May 14, 2024
1 parent 9937b6b commit 0e4c7e9
Show file tree
Hide file tree
Showing 24 changed files with 75 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ public NvxApplicationAudioReceiver(string key, NvxApplicationDeviceAudioConfig c

AddPostActivationAction(() =>
{
var feedback = Device.Feedbacks[CurrentSecondaryAudioStream.RouteNameKey] as StringFeedback;
var audioSourceFeedback = Device.Feedbacks[AudioInputFeedback.Key] as StringFeedback;
if (feedback == null)
if (Device.Feedbacks[CurrentSecondaryAudioStream.RouteNameKey] is not StringFeedback feedback)
throw new NullReferenceException(CurrentSecondaryAudioStream.RouteNameKey);
if (audioSourceFeedback == null)
if (Device.Feedbacks[AudioInputFeedback.Key] is not StringFeedback audioSourceFeedback)
throw new NullReferenceException(AudioInputFeedback.Key);
var currentRouteFb = new IntFeedback(Key + "--appRouteAudioCurrentId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ public NvxApplicationVideoReceiver(string key, NvxApplicationDeviceVideoConfig c
AspectRatioMode = new IntFeedback(() => 0);
EdidManufacturer = new StringFeedback(() => string.Empty);
if (!(Device is IHdmiOutput hdmiOut))
if (Device is not IHdmiOutput hdmiOut)
return;
DisabledByHdcp = hdmiOut.DisabledByHdcp;
HorizontalResolution = hdmiOut.HorizontalResolution;
EdidManufacturer = hdmiOut.EdidManufacturer;
if (!(Device is IVideowallMode aspect))
if (Device is not IVideowallMode aspect)
return;
AspectRatioMode = aspect.VideoAspectRatioMode;
Expand Down
18 changes: 6 additions & 12 deletions src/NvxEpi/Application/Entities/NvxApplicationVideoTransmitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ private void LinkInputValues(string routingPortKey)

if (string.IsNullOrEmpty(routingPortKey))
{
var hdmiInput = Device as IHdmiInput;
if (hdmiInput == null)
if (Device is not IHdmiInput hdmiInput)
return;

HdmiSyncDetected = hdmiInput.SyncDetected[1];
Expand All @@ -125,8 +124,7 @@ private void LinkInputValues(string routingPortKey)
}
else if (routingPortKey.Equals(DeviceInputEnum.Hdmi1.Name, StringComparison.OrdinalIgnoreCase))
{
var hdmiInput = Device as IHdmiInput;
if (hdmiInput == null)
if (Device is not IHdmiInput hdmiInput)
return;

HdmiSyncDetected = hdmiInput.SyncDetected[1];
Expand All @@ -135,8 +133,7 @@ private void LinkInputValues(string routingPortKey)
}
else if (routingPortKey.Equals(DeviceInputEnum.Hdmi2.Name, StringComparison.OrdinalIgnoreCase))
{
var hdmiInput = Device as IHdmiInput;
if (hdmiInput == null)
if (Device is not IHdmiInput hdmiInput)
return;

_useHdmiInput2 = true;
Expand All @@ -146,12 +143,10 @@ private void LinkInputValues(string routingPortKey)
}
else if (routingPortKey.Equals(DeviceInputEnum.Automatic.Name, StringComparison.OrdinalIgnoreCase))
{
var hdmiInput = Device as IHdmiInput;
if (hdmiInput == null)
if (Device is not IHdmiInput hdmiInput)
return;

var hdmiSwitcher = Device as ICurrentVideoInput;
if (hdmiSwitcher == null)
if (Device is not ICurrentVideoInput hdmiSwitcher)
return;

HdmiSyncDetected = hdmiInput.SyncDetected[1];
Expand All @@ -173,8 +168,7 @@ public BoolFeedback IsOnline

public void SetHdcpState(ushort state)
{
var hdmiInput = Device as IHdmiInput;
if (hdmiInput == null)
if (Device is not IHdmiInput hdmiInput)
return;

if (_useHdmiInput2)
Expand Down
5 changes: 1 addition & 4 deletions src/NvxEpi/Devices/NvxXioDirector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ public class NvxXioDirector : EssentialsDevice, INvxDirector, IOnline

public NvxXioDirector(string key, string name, DmXioDirectorBase hardware) : base(key, name)
{
if (hardware == null)
throw new ArgumentNullException("hardware");

_hardware = hardware;
_hardware = hardware ?? throw new ArgumentNullException("hardware");
_isOnline = new BoolFeedback("BuildFeedbacks", () => _hardware.IsOnline);
_hardware.OnlineStatusChange += (device, args) => _isOnline.FireUpdate();
}
Expand Down
10 changes: 3 additions & 7 deletions src/NvxEpi/Enums/Enumeration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ public static IEnumerable<TEnum> GetAll()

public override bool Equals(object obj)
{
var otherValue = obj as Enumeration<TEnum>;

if (otherValue == null)
if (obj is not Enumeration<TEnum> otherValue)
return false;

bool typeMatches = GetType().GetCType() == obj.GetType().GetCType();
Expand All @@ -56,8 +54,7 @@ public int CompareTo(object other)
{
if (other == null) return 1;

var otherEnum = other as Enumeration<TEnum>;
if (otherEnum != null)
if (other is Enumeration<TEnum> otherEnum)
return Value.CompareTo(otherEnum.Value);

throw new ArgumentException("Object is not an Enum Class");
Expand Down Expand Up @@ -113,8 +110,7 @@ private static void CheckAll()
_lock.Enter();
try
{
if (_all == null)
_all = GetAllOptions();
_all ??= GetAllOptions();
}
finally
{
Expand Down
5 changes: 1 addition & 4 deletions src/NvxEpi/Factories/Nvx35XDeviceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public Nvx35XDeviceFactory()
{
MinimumEssentialsFrameworkVersion = MinumumEssentialsVersion;

if (_typeNames == null)
{
_typeNames = new List<string>
_typeNames ??= new List<string>
{
"dmnvx350",
"dmnvx350c",
Expand All @@ -26,7 +24,6 @@ public Nvx35XDeviceFactory()
"dmnvx352",
"dmnvx352c",
};
}

TypeNames = _typeNames.ToList();
}
Expand Down
5 changes: 1 addition & 4 deletions src/NvxEpi/Factories/Nvx36XDeviceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public Nvx36XDeviceFactory()
{
MinimumEssentialsFrameworkVersion = MinumumEssentialsVersion;

if (_typeNames == null)
{
_typeNames = new List<string>
_typeNames ??= new List<string>
{
"dmnvx360",
"dmnvx360c",
Expand All @@ -26,7 +24,6 @@ public Nvx36XDeviceFactory()
"dmnvxe760",
"dmnvxe760c",
};
}

TypeNames = _typeNames.ToList();
}
Expand Down
54 changes: 18 additions & 36 deletions src/NvxEpi/Factories/NvxBaseDeviceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvx350((uint)props.DeviceId, domain, !props.DeviceIsTransmitter())
: new DmNvx350((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter());
};
Expand All @@ -55,9 +54,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvx350C((uint)props.DeviceId, domain, !props.DeviceIsTransmitter())
: new DmNvx350C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter());
};
Expand All @@ -72,9 +70,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvx351((uint)props.DeviceId, domain, !props.DeviceIsTransmitter())
: new DmNvx351((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter());
};
Expand All @@ -89,9 +86,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvx351C((uint)props.DeviceId, domain, !props.DeviceIsTransmitter())
: new DmNvx351C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter());
};
Expand All @@ -106,9 +102,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvx352((uint)props.DeviceId, domain, !props.DeviceIsTransmitter())
: new DmNvx352((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter());
};
Expand All @@ -123,9 +118,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvx352C((uint)props.DeviceId, domain, !props.DeviceIsTransmitter())
: new DmNvx352C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter());
};
Expand All @@ -140,9 +134,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvx360((uint)props.DeviceId, domain, !props.DeviceIsTransmitter())
: new DmNvx360((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter());
};
Expand All @@ -157,9 +150,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvx360C((uint)props.DeviceId, domain, !props.DeviceIsTransmitter())
: new DmNvx360C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter());
};
Expand All @@ -174,9 +166,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvx363((uint)props.DeviceId, domain, !props.DeviceIsTransmitter())
: new DmNvx363((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter());
};
Expand All @@ -191,9 +182,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvx363C((uint)props.DeviceId, domain, !props.DeviceIsTransmitter())
: new DmNvx363C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault(), !props.DeviceIsTransmitter());
};
Expand All @@ -208,9 +198,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvxD30((uint)props.DeviceId, domain)
: new DmNvxD30((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault());
};
Expand All @@ -225,9 +214,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvxD30C((uint)props.DeviceId, domain)
: new DmNvxD30C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault());
};
Expand All @@ -242,9 +230,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvxE30((uint)props.DeviceId, domain)
: new DmNvxE30((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault());
};
Expand All @@ -259,9 +246,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvxE30C((uint)props.DeviceId, domain)
: new DmNvxE30C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault());
};
Expand All @@ -276,9 +262,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvxE31((uint)props.DeviceId, domain)
: new DmNvxE31((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault());
};
Expand All @@ -293,9 +278,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvxE31C((uint)props.DeviceId, domain)
: new DmNvxE31C((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault());
};
Expand All @@ -310,9 +294,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvxE760((uint)props.DeviceId, domain)
: new DmNvxE760((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault());
};
Expand All @@ -327,9 +310,8 @@ protected static Func<DmNvxBaseClass> GetDeviceBuildAction(string type, NvxDevic
return () =>
{
var xio = GetDirector(props.ParentDeviceKey);
DmXioDirectorBase.DmXioDomain domain;
return xio.Hardware.Domain.TryGetValue(props.DomainId, out domain)
return xio.Hardware.Domain.TryGetValue(props.DomainId, out DmXioDirectorBase.DmXioDomain domain)
? new DmNvxE760((uint)props.DeviceId, domain)
: new DmNvxE760((uint)props.DeviceId, xio.Hardware.Domain.Values.FirstOrDefault());
};
Expand Down
5 changes: 1 addition & 4 deletions src/NvxEpi/Factories/NvxD3XDeviceFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ public NvxD3XDeviceFactory()
{
MinimumEssentialsFrameworkVersion = MinumumEssentialsVersion;

if (_typeNames == null)
{
_typeNames = new List<string>
_typeNames ??= new List<string>
{
"dmnvxd30",
"dmnvxd30c",
};
}

TypeNames = _typeNames.ToList();
}
Expand Down
Loading

0 comments on commit 0e4c7e9

Please sign in to comment.