2010-10-18 14 views
5

मैं एक सी # वर्ग कि एक छोटे से की तरह लग रहा है के लिए एक IronPython विधि नियत:एक सी # प्रतिनिधि

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 स्क्रिप्ट अनुप्रयोग है कि

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 को (आयरनपीथन के बाहर) कहा जाता है, तो डिफ़ॉल्ट विधि चलती है।

मुझे पता है कि स्क्रिप्ट चल रही है क्योंकि लिपि के अन्य भाग काम करते हैं।

मुझे यह कैसे करना चाहिए?

उत्तर

11

मैं कुछ आगे Googling किया था और 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) 
+0

एक पुरानी पोस्ट का जवाब देने हैं, लेकिन आप नहीं होगा इसके लिए कहीं से भी IDataSource नाम आयात करने की आवश्यकता है? –

संबंधित मुद्दे