vb.net - Implementing Events in a Base Class -
consider following objects:
public mustinherit class filerepository public mustoverride sub savestringtofile(byval filetext string, byval filepath string) public event filesaved(byref sender object, byval eventargs eventargs) end class public class xmlfilerepository inherits filerepository public overrides sub savestringtofile(byval filetext string, byval filepath string) end sub private sub xmlfilerepository_filesaved(byref sender object, byval eventargs system.eventargs) handles me.filesaved end sub end class
i want base class raise filesaved
event in it's implentation of savestringtofile
once it's saved file. in vb.net can't have derived class raise base classes event. suppose can treat xmlfilerepository_filesaved
standard function call , have savestringtofile
implementation call directly think i'm approaching problem wrong way. great!
add overridable sub in base class raises base classes filesaved-event:
public mustinherit class filerepository public mustoverride sub savestringtofile(byval filetext string, byval filepath string) public event filesaved(byval filetext string, byval filepath string) protected overridable sub onfilesaved(byval filetext string, byval filepath string) raiseevent filesaved(filetext, filepath) end sub end class public class xmlfilerepository inherits filerepository public overrides sub savestringtofile(byval filetext string, byval filepath string) mybase.onfilesaved(filetext, filepath) end sub private sub xmlfilerepository_filesaved(byval filetext string, byval filepath string) handles mybase.filesaved end sub end class
Comments
Post a Comment