Use type check syntax in BizInvoke rather than `GetType` + `==`
This commit is contained in:
parent
a9a951ba1b
commit
a3f8f04d20
|
@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue