我试图从继承的类中隐藏一个事件,但不是通过 EditorBrowserable 属性。
我有一个从 FileSystemWatcher 继承的 DelayedFileSystemWatcher,我需要隐藏 Changed、Created、Deleted 和 Renamed 事件并将它们设为私有(private)。
我试过这个,但它不起作用:
/// <summary>
/// Do not use
/// </summary>
private new event FileSystemEventHandler Changed;
XML 注释未显示在 IntelliSense 中(显示了原始信息)。但是,如果我将访问修饰符更改为 public,则 XML 注释会显示在 IntelliSense 中。
欢迎任何帮助。
最佳答案
您不想使用它,但它可以轻松解决您的问题:
class MyWatcher : FileSystemWatcher {
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
private new event FileSystemEventHandler Changed;
// etc..
}
你唯一能做的就是封装它。这是可行的,该类只是没有那么多成员,您正在消除其中的几个:
class MyWatcher : Component {
private FileSystemWatcher watcher = new FileSystemWatcher();
public MyWatcher() {
watcher.EnableRaisingEvents = true;
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
// etc..
}
public string Path {
get { return watcher.Path; }
set { watcher.Path = value; }
}
// etc..
}
关于c# - 隐藏在继承类中的事件不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6636906/