Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So you want to <strong>inherit</strong> all the functionalities of the <code>FileSystemWatcher</code>, while adding your properties? Try inheriting the class:</p> <pre><code>public class MyFileSystemWatcher : FileSystemWatcher { public string XmlConfigPath { get; set; } } </code></pre> <p>and after that you can use your new class on every place where you would use the <code>System.IO.FileSystemWatcher</code>, like this:</p> <pre><code>MyFileSystemWatcher fsw = new MyFileSystemWatcher(); fsw.XmlConfigPath = @"C:\config.xml"; fsw.Path = @"C:\Watch\Path\*.*"; </code></pre> <hr> <p>Another approach would be to make a class that will both have the config file location , and the FileSystemWatcher object as a property, along these lines:</p> <pre><code>public class MyFileSystemWatcherManager { public string XmlConfigPath { get; set; } public FileSystemWatcher Watcher { get; set; } public MyFileSystemWatcherManager() { Watcher = new FileSystemWatcher(); } } </code></pre> <p>and with usage like this:</p> <pre><code>MyFileSystemWatcherManager manager = new MyFileSystemWatcherManager(); manager.XmlConfigPath = @"C:\config.xml"; manager.Watcher.Path = @"C:\Watch\Path\*.*"; </code></pre> <p>Composition is possible even when the base class cannot be inherited, and it's generally preferred from an OO perspective, since most of the code that uses your class will rely only on your class, and not on the base class. However, when you do want to inherit <strong>all</strong> of the base behaviours and just add some (well-defined) extras, inheritance is the simpler and more tightly-coupled solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload