c# - Using .NET is it possible to assign a custom property to a built in object such as FileSystemWatcher? -


is possible add custom property object part of .net framework?

i know how if giving class i'd wrote property, adding custom property filesystemwatcher class?

i'm loading in path want watch xml file, want add property store more information, in case location of config file. can add property filesystemwatcher class itself?

so want inherit functionalities of filesystemwatcher, while adding properties? try inheriting class:

public class myfilesystemwatcher : filesystemwatcher {     public string xmlconfigpath { get; set; } } 

and after can use new class on every place use system.io.filesystemwatcher, this:

myfilesystemwatcher fsw = new myfilesystemwatcher(); fsw.xmlconfigpath = @"c:\config.xml"; fsw.path = @"c:\watch\path\*.*"; 

another approach make class both have config file location , , filesystemwatcher object property, along these lines:

public class myfilesystemwatchermanager {     public string xmlconfigpath { get; set; }     public filesystemwatcher watcher { get; set; }      public myfilesystemwatchermanager()     {         watcher = new filesystemwatcher();     } } 

and usage this:

myfilesystemwatchermanager manager = new myfilesystemwatchermanager(); manager.xmlconfigpath = @"c:\config.xml"; manager.watcher.path = @"c:\watch\path\*.*"; 

composition possible when base class cannot inherited, , it's preferred oo perspective, since of code uses class rely on class, , not on base class. however, when want inherit all of base behaviours , add (well-defined) extras, inheritance simpler , more tightly-coupled solution.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -