<bdo id='aTbEL'></bdo><ul id='aTbEL'></ul>
      <tfoot id='aTbEL'></tfoot>
      <i id='aTbEL'><tr id='aTbEL'><dt id='aTbEL'><q id='aTbEL'><span id='aTbEL'><b id='aTbEL'><form id='aTbEL'><ins id='aTbEL'></ins><ul id='aTbEL'></ul><sub id='aTbEL'></sub></form><legend id='aTbEL'></legend><bdo id='aTbEL'><pre id='aTbEL'><center id='aTbEL'></center></pre></bdo></b><th id='aTbEL'></th></span></q></dt></tr></i><div id='aTbEL'><tfoot id='aTbEL'></tfoot><dl id='aTbEL'><fieldset id='aTbEL'></fieldset></dl></div>
      <legend id='aTbEL'><style id='aTbEL'><dir id='aTbEL'><q id='aTbEL'></q></dir></style></legend>

      <small id='aTbEL'></small><noframes id='aTbEL'>

      1. 将 IronPython 方法分配给 C# 委托

        Assigning an IronPython method to a C# delegate(将 IronPython 方法分配给 C# 委托)
      2. <i id='pRXpC'><tr id='pRXpC'><dt id='pRXpC'><q id='pRXpC'><span id='pRXpC'><b id='pRXpC'><form id='pRXpC'><ins id='pRXpC'></ins><ul id='pRXpC'></ul><sub id='pRXpC'></sub></form><legend id='pRXpC'></legend><bdo id='pRXpC'><pre id='pRXpC'><center id='pRXpC'></center></pre></bdo></b><th id='pRXpC'></th></span></q></dt></tr></i><div id='pRXpC'><tfoot id='pRXpC'></tfoot><dl id='pRXpC'><fieldset id='pRXpC'></fieldset></dl></div>

        • <small id='pRXpC'></small><noframes id='pRXpC'>

          <legend id='pRXpC'><style id='pRXpC'><dir id='pRXpC'><q id='pRXpC'></q></dir></style></legend>

              <tbody id='pRXpC'></tbody>
              <bdo id='pRXpC'></bdo><ul id='pRXpC'></ul>
              <tfoot id='pRXpC'></tfoot>
                  本文介绍了将 IronPython 方法分配给 C# 委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个 C# 类,看起来有点像:

                  I have a C# class that looks a little like:

                  public class MyClass
                  {
                      private Func<IDataCource, object> processMethod = (ds) =>
                                                                            {
                                                                              //default method for the class
                                                                            }
                  
                      public Func<IDataCource, object> ProcessMethod
                      {
                          get{ return processMethod; }
                          set{ processMethod = value; }
                      }
                  
                      /* Other details elided */
                  }
                  

                  我有一个 IronPython 脚本,它可以在看起来像这样的应用程序中运行

                  And I have an IronPython script that gets run in the application that looks like

                  from MyApp import myObj #instance of MyClass
                  
                  def OtherMethod(ds):
                      if ds.Data.Length > 0 :
                          quot = sum(ds.Data.Real)/sum(ds.Data.Imag)
                          return quot
                      return 0.0
                  
                  myObj.ProcessMethod = OtherMethod
                  

                  但是当 ProcessMethod 被调用时(在 IronPython 之外),在这个赋值之后,默认的方法就会运行.

                  But when ProcessMethod gets called (outside of IronPython), after this assignment, the default method is run.

                  我知道脚本正在运行,因为脚本的其他部分有效.

                  I know the script is run because other parts of the script work.

                  我应该怎么做?

                  推荐答案

                  我做了一些进一步的谷歌搜索,发现了一个关于 IronPython 黑暗角落的页面:http://www.voidspace.org.uk/ironpython/dark-corners.shtml

                  I did some further Googling and found a page about the darker corners of IronPython: http://www.voidspace.org.uk/ironpython/dark-corners.shtml

                  我应该做的是:

                  from MyApp import myObj #instance of MyClass
                  import clr
                  clr.AddReference('System.Core')
                  from System import Func
                  
                  def OtherMethod(ds):
                      if ds.Data.Length > 0 :
                          quot = sum(ds.Data.Real)/sum(ds.Data.Imag)
                          return quot
                      return 0.0
                  
                  myObj.ProcessMethod = Func[IDataSource, object](OtherMethod)
                  

                  这篇关于将 IronPython 方法分配给 C# 委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)

                  <small id='A8HUp'></small><noframes id='A8HUp'>

                    <tbody id='A8HUp'></tbody>

                    <tfoot id='A8HUp'></tfoot>

                        <legend id='A8HUp'><style id='A8HUp'><dir id='A8HUp'><q id='A8HUp'></q></dir></style></legend>
                            <bdo id='A8HUp'></bdo><ul id='A8HUp'></ul>
                            <i id='A8HUp'><tr id='A8HUp'><dt id='A8HUp'><q id='A8HUp'><span id='A8HUp'><b id='A8HUp'><form id='A8HUp'><ins id='A8HUp'></ins><ul id='A8HUp'></ul><sub id='A8HUp'></sub></form><legend id='A8HUp'></legend><bdo id='A8HUp'><pre id='A8HUp'><center id='A8HUp'></center></pre></bdo></b><th id='A8HUp'></th></span></q></dt></tr></i><div id='A8HUp'><tfoot id='A8HUp'></tfoot><dl id='A8HUp'><fieldset id='A8HUp'></fieldset></dl></div>