Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7436733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:17:16+00:00 2026-05-29T10:17:16+00:00

So I am hosting IronPython in my C# application. IronPhyton is used to implement

  • 0

So I am hosting IronPython in my C# application. IronPhyton is used to implement a DSL for users. The DSL syntax should be something like this:

Ping(Message = "testOne1")

The hosting code looks like:

var engine = Python.CreateEngine();
var scope = engine.CreateScope();

Action<string> ping = (message) => Console.WriteLine(message.ToString());            
scope.SetVariable("Ping", ping);
var script = @"
Ping(Message = ""testOne1"")
";
engine.Execute(script, scope);

But this does not work because Action<string> does not keep name of the argument. Calling it without the parameter name works as expected:

Ping("testOne1")

How do I store a function and call it with named arguments?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:17:18+00:00Added an answer on May 29, 2026 at 10:17 am

    To use named arguments you’ll have to define the method statically. For example, I’ll just put all DSL operations into an Operations static class.

    public static class Operations {
      public static void Ping(string Message) {
        Console.WriteLine(Message);
      }
    }
    

    Then named arguments will work:

    var engine = Python.CreateEngine();
    var scope = engine.CreateScope();
    
    // Load the assembly where the operations are defined.
    engine.Runtime.LoadAssembly(Assembly.GetExecutingAssembly());
    
    // Import the operations modules, settings their names as desired.
    engine.Execute(@"
    from Operations import Ping
    ", scope);
    
    // Now named arguments will work...
    var script = @"
    Ping(Message = ""Ping!"")
    ";
    
    engine.Execute(script, scope);
    

    Now if I could give you some advise; I’d prefer to implement the actual Python API in Python, and have that call back into my .NET code as needed. For example, instead of having the “operations” defined in C#, you’d have an Operations.py file which defines your Python DSL:

    # Get access to your .NET API
    import clr
    clr.AddReference("MyAPI")
    import MyAPI
    
    # Define the Ping call to call into your .NET API
    def Ping(Message):
      MyAPI.Ping(Message)
    

    And your hosting code doesn’t need to change at all.

    Both are valid solutions, but the last one lets you iterate on your DSL easily.

    Good luck!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm hosting IronPython 2.0 in a C#/Winforms application. I would like Python to be
I'm hosting my IronPython in a C# webapp like so: var engine = Python.CreateEngine();
I'm trying to create ASP.NET syntax highlighter for my blog with IronPython.Hosting and Pygments.
For an image hosting web application: For my stored images, is it feasible to
I am hosting SpiderMonkey in a current project and would like to have template
My hosting sent me email saying I have set the session.save_path = /home/users/web/b1475/moo.youraccount/cgi-bin/tmp for
I am hosting some video on my web and I would like to make
I am currently hosting a low-volume WSS 3.0 application on a virtual server for
What is hosting the Silverlight application when running out of browser? I can imagine
Instead of hosting my company's source code on GitHub, I would like to host

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.