Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
F# 在F中将成员定义为事件处理程序#_F# - Fatal编程技术网

F# 在F中将成员定义为事件处理程序#

F# 在F中将成员定义为事件处理程序#,f#,F#,这可能被问了好几次,但我就是找不到一个例子 我的目标是为事件定义一个事件处理程序,该处理程序应该是类的成员。换句话说,我不想使用函数,因为我需要访问实例变量和成员 我尝试过的最新版本: namespace A type ValueList<'TValueItem when 'TValueItem :> IValueItem>() = inherit System.Collections.ObjectModel.ObservableCollection&l

这可能被问了好几次,但我就是找不到一个例子

我的目标是为事件定义一个事件处理程序,该处理程序应该是类的成员。换句话说,我不想使用函数,因为我需要访问实例变量和成员

我尝试过的最新版本:

namespace A
    type ValueList<'TValueItem when 'TValueItem :> IValueItem>() =
        inherit System.Collections.ObjectModel.ObservableCollection<'TValueItem>()

        // This is causing error: The value or constructor 'ValueList_CollectionChanged' is not defined
        let collectionChangedHandler = new System.Collections.Specialized.NotifyCollectionChangedEventHandler(ValueList_CollectionChanged)

        // Constructor code
        do base.CollectionChanged.AddHandler(collectionChangedHandler)

        // Handles collection changed events for data items
        member this.ValueList_CollectionChanged(sender : obj, e : System.Collections.Specialized.NotifyCollectionChangedEventArgs) =
            // The code I want to run goes here
            ...
名称空间A
键入ValueList IValueItem>()=

inherit System.Collections.ObjectModel.ObservableCollection看起来像是在寻找自标识符语法:

type ValueList<'TValueItem when 'TValueItem :> IValueItem>() as this =
要使此方法保持有效,还需要将
ValueList\u CollectionChanged
方法设置为当前格式:

member this.ValueList_CollectionChanged (sender : obj) (e : System.Collections.Specialized.NotifyCollectionChangedEventArgs) =
作为使用curried参数的替代方法,您可以使用lambda转换处理程序实例化的参数,例如
.NotifyCollectionChangedEventHandler(fun sender e->this.(…)

member this.ValueList_CollectionChanged (sender : obj) (e : System.Collections.Specialized.NotifyCollectionChangedEventArgs) =