More pattern matching.

This commit is contained in:
2022-11-14 01:49:09 +00:00
parent e6db6032f3
commit a02220902c
8 changed files with 11 additions and 22 deletions

View File

@@ -57,8 +57,7 @@ public static class ATIP
{ {
public static CDATIP Decode(byte[] CDATIPResponse) public static CDATIP Decode(byte[] CDATIPResponse)
{ {
if(CDATIPResponse == null || if(CDATIPResponse is not { Length: > 4 })
CDATIPResponse.Length <= 4)
return null; return null;
var decoded = new CDATIP(); var decoded = new CDATIP();

View File

@@ -93,8 +93,7 @@ public static class CDTextOnLeadIn
public static CDText? Decode(byte[] CDTextResponse) public static CDText? Decode(byte[] CDTextResponse)
{ {
if(CDTextResponse == null || if(CDTextResponse is not { Length: > 4 })
CDTextResponse.Length <= 4)
return null; return null;
var decoded = new CDText var decoded = new CDText

View File

@@ -69,8 +69,7 @@ public static class FullTOC
public static CDFullTOC? Decode(byte[] CDFullTOCResponse) public static CDFullTOC? Decode(byte[] CDFullTOCResponse)
{ {
if(CDFullTOCResponse == null || if(CDFullTOCResponse is not { Length: > 4 })
CDFullTOCResponse.Length <= 4)
return null; return null;
var decoded = new CDFullTOC var decoded = new CDFullTOC

View File

@@ -56,8 +56,7 @@ public static class PMA
{ {
public static CDPMA? Decode(byte[] CDPMAResponse) public static CDPMA? Decode(byte[] CDPMAResponse)
{ {
if(CDPMAResponse == null || if(CDPMAResponse is not { Length: > 4 })
CDPMAResponse.Length <= 4)
return null; return null;
var decoded = new CDPMA var decoded = new CDPMA

View File

@@ -55,8 +55,7 @@ public static class Session
{ {
public static CDSessionInfo? Decode(byte[] CDSessionInfoResponse) public static CDSessionInfo? Decode(byte[] CDSessionInfoResponse)
{ {
if(CDSessionInfoResponse == null || if(CDSessionInfoResponse is not { Length: > 4 })
CDSessionInfoResponse.Length <= 4)
return null; return null;
var decoded = new CDSessionInfo var decoded = new CDSessionInfo

View File

@@ -58,8 +58,7 @@ public static class TOC
{ {
public static CDTOC? Decode(byte[] CDTOCResponse) public static CDTOC? Decode(byte[] CDTOCResponse)
{ {
if(CDTOCResponse == null || if(CDTOCResponse is not { Length: > 4 })
CDTOCResponse.Length <= 4)
return null; return null;
var decoded = new CDTOC var decoded = new CDTOC

View File

@@ -151,8 +151,7 @@ public static class Apple2
/// <param name="data">5and3 encoded data.</param> /// <param name="data">5and3 encoded data.</param>
public static byte[] Decode5and3(byte[] data) public static byte[] Decode5and3(byte[] data)
{ {
if(data == null || if(data is not { Length: 410 })
data.Length != 410)
return null; return null;
var buffer = new byte[data.Length]; var buffer = new byte[data.Length];
@@ -189,8 +188,7 @@ public static class Apple2
/// <param name="data">6and2 encoded data.</param> /// <param name="data">6and2 encoded data.</param>
public static byte[] Decode6and2(byte[] data) public static byte[] Decode6and2(byte[] data)
{ {
if(data == null || if(data is not { Length: 342 })
data.Length != 342)
return null; return null;
var buffer = new byte[data.Length]; var buffer = new byte[data.Length];

View File

@@ -47,8 +47,7 @@ public static class LisaTag
/// <returns>Decoded tag in Sony's format</returns> /// <returns>Decoded tag in Sony's format</returns>
public static SonyTag? DecodeSonyTag(byte[] tag) public static SonyTag? DecodeSonyTag(byte[] tag)
{ {
if(tag == null || if(tag is not { Length: 12 })
tag.Length != 12)
return null; return null;
var snTag = new SonyTag var snTag = new SonyTag
@@ -74,8 +73,7 @@ public static class LisaTag
/// <returns>Decoded tag in Profile's format</returns> /// <returns>Decoded tag in Profile's format</returns>
public static ProfileTag? DecodeProfileTag(byte[] tag) public static ProfileTag? DecodeProfileTag(byte[] tag)
{ {
if(tag == null || if(tag is not { Length: 20 })
tag.Length != 20)
return null; return null;
var phTag = new ProfileTag(); var phTag = new ProfileTag();
@@ -122,8 +120,7 @@ public static class LisaTag
/// <returns>Decoded tag in Priam's format</returns> /// <returns>Decoded tag in Priam's format</returns>
public static PriamTag? DecodePriamTag(byte[] tag) public static PriamTag? DecodePriamTag(byte[] tag)
{ {
if(tag == null || if(tag is not { Length: 24 })
tag.Length != 24)
return null; return null;
var pmTag = new PriamTag(); var pmTag = new PriamTag();