Use type check syntax in BizInvoke rather than `GetType` + `==`

This commit is contained in:
James Groom 2024-05-06 20:39:52 +10:00 committed by GitHub
parent a9a951ba1b
commit a3f8f04d20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 9 deletions

View File

@ -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<object>());
return new(o.GetType().GetConstructor(Type.EmptyTypes)!, Array.Empty<object>());
}
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}");
}
}
}