Assigning an IronPython method to a C# delegate

前端 未结 1 1772
长情又很酷
长情又很酷 2020-12-18 04:28

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

public class MyClass
{
    private Func processMethod = (ds) =>
                            


        
相关标签:
1条回答
  • 2020-12-18 05:11

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

    What I should be doing is this:

    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)
    
    0 讨论(0)
提交回复
热议问题