Skip to content

Commit d02b3bf

Browse files
committed
not all events have Add method
fixes pythonnet#2405
1 parent 32051cb commit d02b3bf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/runtime/ClassManager.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,13 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p
290290

291291
internal static bool ShouldBindMethod(MethodBase mb)
292292
{
293+
if (mb is null) throw new ArgumentNullException(nameof(mb));
293294
return (mb.IsPublic || mb.IsFamily || mb.IsFamilyOrAssembly);
294295
}
295296

296297
internal static bool ShouldBindField(FieldInfo fi)
297298
{
299+
if (fi is null) throw new ArgumentNullException(nameof(fi));
298300
return (fi.IsPublic || fi.IsFamily || fi.IsFamilyOrAssembly);
299301
}
300302

@@ -326,7 +328,7 @@ internal static bool ShouldBindProperty(PropertyInfo pi)
326328

327329
internal static bool ShouldBindEvent(EventInfo ei)
328330
{
329-
return ShouldBindMethod(ei.GetAddMethod(true));
331+
return ei.GetAddMethod(true) is { } add && ShouldBindMethod(add);
330332
}
331333

332334
private static ClassInfo GetClassInfo(Type type, ClassBase impl)

0 commit comments

Comments
 (0)