c# - Can i combine two or more different events for one method? -
i'm using filesystemwatcher.
it's easy when combining events same type, here (filesystemeventargs), , saw passing parameters event handler, passing event event method, don't know how.
before, want this:
private void systemwatch(object sender, system.io.renamedeventargs e, system.io.filesystemeventargs f) but can't change filesystemeventhandler or renamedeventhandler delegate, there alternative way ?
delegates, found in events, define method signature expected called. such, events differing signatures cannot implicitly call method differing signature.
one potential workaround might use dynamic lambda method perform translation:
watcher.created += (s, a) => systemwatch(s, null, a); watcher.renamed += (s, a) => systemwatch(s, a, null); edit:
after further consideration, mcgarnagle stated, renamedeventsargs inherits filesystemeventargs. should able handle both scenarios using single event handler:
private static void oncreatedorrenamed(object source, filesystemeventargs e) you can tell operation checking type of e:
if (e renamedeventargs) ... else ...
Comments
Post a Comment