FileSystemEventHandler arg type
-
I need to create an instance of FileSystemEventHandler inside a function, using a parameter passed into that function. FileSystemEventHandler takes an Object type that represents the method called by the FileSystemEventHandler delegate. This would be easy with C++ since I can use a pointer to a method, but I'm lost in how to do it in C#. :confused: How can I pass this into my function so I can create the instance? For example: Where OnChanged is the method for the delegate to call.
private void CallingFunc()
{
MyFunc(OnChanged); // ? How to prepresent this method?
}// ? what type do I use as the input parameter here?
private void MyFunc(SomeType theMethodToCall)
{
FileSystemEventHandler(theMethodToCall);
}TIA :)
-
I need to create an instance of FileSystemEventHandler inside a function, using a parameter passed into that function. FileSystemEventHandler takes an Object type that represents the method called by the FileSystemEventHandler delegate. This would be easy with C++ since I can use a pointer to a method, but I'm lost in how to do it in C#. :confused: How can I pass this into my function so I can create the instance? For example: Where OnChanged is the method for the delegate to call.
private void CallingFunc()
{
MyFunc(OnChanged); // ? How to prepresent this method?
}// ? what type do I use as the input parameter here?
private void MyFunc(SomeType theMethodToCall)
{
FileSystemEventHandler(theMethodToCall);
}TIA :)
Not Knuth wrote:
// ? what type do I use as the input parameter here?
I can't tell what you are trying to do but maybe you could use FileSystemEventHandler as the parameter type. Also just guessing here but you may have a design issue. Can't really tell based on your post because:
Not Knuth wrote:
private void MyFunc(SomeType theMethodToCall) { FileSystemEventHandler(theMethodToCall); }
that just doesn't make any sense because you would be creating a handler that is not registered with any event so it's pointless.
led mike
-
Not Knuth wrote:
// ? what type do I use as the input parameter here?
I can't tell what you are trying to do but maybe you could use FileSystemEventHandler as the parameter type. Also just guessing here but you may have a design issue. Can't really tell based on your post because:
Not Knuth wrote:
private void MyFunc(SomeType theMethodToCall) { FileSystemEventHandler(theMethodToCall); }
that just doesn't make any sense because you would be creating a handler that is not registered with any event so it's pointless.
led mike
I was trying to keep the code sample simple. Maybe too simple! This is part of a class that wraps FileSystemWatcher to provide some other functionality that is needed. The situation with the arg for this method arises because I need to be able to set the method(s) to be called by the delegates for the instance of FileSystemWatcher that is wrapped in the class. Thanks for trying to make sense of my sample code!
-
I was trying to keep the code sample simple. Maybe too simple! This is part of a class that wraps FileSystemWatcher to provide some other functionality that is needed. The situation with the arg for this method arises because I need to be able to set the method(s) to be called by the delegates for the instance of FileSystemWatcher that is wrapped in the class. Thanks for trying to make sense of my sample code!
-
Not Knuth wrote:
This is part of a class that wraps FileSystemWatcher
so then that should work yes?
private void MyFunc(FileSystemEventHandler handler)
{
fileSystemWatcher1.Changed += handler;
}led mike