From a3f8f04d200adbea33578a4643d8b7732cba67d1 Mon Sep 17 00:00:00 2001 From: James Groom Date: Mon, 6 May 2024 20:39:52 +1000 Subject: [PATCH] Use type check syntax in BizInvoke rather than `GetType` + `==` --- src/BizHawk.BizInvoke/BizInvokeUtilities.cs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/BizHawk.BizInvoke/BizInvokeUtilities.cs b/src/BizHawk.BizInvoke/BizInvokeUtilities.cs index cd9f1c5481..a70159bfaf 100644 --- a/src/BizHawk.BizInvoke/BizInvokeUtilities.cs +++ b/src/BizHawk.BizInvoke/BizInvokeUtilities.cs @@ -82,19 +82,18 @@ namespace BizHawk.BizInvoke private static CustomAttributeBuilder GetAttributeBuilder(object o) { // anything more clever we can do here? - var t = o.GetType(); - - if (t == typeof(OutAttribute) || t == typeof(InAttribute) || t == typeof(IsReadOnlyAttribute)) + if (o is OutAttribute or InAttribute or IsReadOnlyAttribute) { - return new(t.GetConstructor(Type.EmptyTypes)!, Array.Empty()); + return new(o.GetType().GetConstructor(Type.EmptyTypes)!, Array.Empty()); } - - if (t == typeof(MarshalAsAttribute)) + if (o is MarshalAsAttribute marshalAsAttr) { - return new(t.GetConstructor(new[] { typeof(UnmanagedType) })!, new object[] { ((MarshalAsAttribute)o).Value }); + return new( + typeof(MarshalAsAttribute).GetConstructor(new[] { typeof(UnmanagedType) })!, + new object[] { marshalAsAttr.Value } + ); } - - throw new InvalidOperationException($"Unknown parameter attribute {t.Name}"); + throw new InvalidOperationException($"parameter of a BizInvoke method had unknown attribute {o.GetType().FullName}"); } } }