Fix crash when event does not have `Add` method and improve message for some other internal errors by lostmsu · Pull Request #2409 · pythonnet/pythonnet · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
4 changes: 3 additions & 1 deletion src/runtime/ClassManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,13 @@ internal static void InitClassBase(Type type, ClassBase impl, ReflectedClrType p

internal static bool ShouldBindMethod(MethodBase mb)
{
if (mb is null) throw new ArgumentNullException(nameof(mb));
return (mb.IsPublic || mb.IsFamily || mb.IsFamilyOrAssembly);
}

internal static bool ShouldBindField(FieldInfo fi)
{
if (fi is null) throw new ArgumentNullException(nameof(fi));
return (fi.IsPublic || fi.IsFamily || fi.IsFamilyOrAssembly);
}

Expand Down Expand Up @@ -326,7 +328,7 @@ internal static bool ShouldBindProperty(PropertyInfo pi)

internal static bool ShouldBindEvent(EventInfo ei)
{
return ShouldBindMethod(ei.GetAddMethod(true));
return ei.GetAddMethod(true) is { } add && ShouldBindMethod(add);
}

private static ClassInfo GetClassInfo(Type type, ClassBase impl)
Expand Down
9 changes: 9 additions & 0 deletions src/runtime/InternalPythonnetException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace Python.Runtime;

public class InternalPythonnetException : Exception
{
public InternalPythonnetException(string message, Exception innerException)
: base(message, innerException) { }
}
31 changes: 19 additions & 12 deletions src/runtime/Types/ReflectedClrType.cs