Skip to content

Support to call C# named parameters from Python #849

Description

@Lexmaul

Hi,
this is a change request:

Environment

  • Pythonnet version: 2.3.0.0
  • Python version: 3.6.5 32-bit
  • Operating System: Win 10

Details

In a python module, we want to call a C# Method, that has named optional parameters. But these are ignored.
Reason: The MethodBinder.Bind(IntPtr inst, IntPtr args, IntPtr kw, MethodBase info, MethodInfo[] methodinfo) Method ignores the passed python keyword-arguments. But instead, it should assign them to the C# named parameters, if appropriate. Can you extend pythonnet to support named parameters?

snip

  • C#
public class LibWithDefault
{
    public static string FuncWithDefault(int x, object b = null)
    {
        return $"x: {x} b: {b} ";
    }
}
  • Python
import clr
clr.AddReference("CS_DefaultParam")
from CS_DefaultParam import LibWithDefault
res = LibWithDefault.FuncWithDefault(x=3, b=4)
print(res)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions