@@ -40,11 +40,11 @@ public enum ColorTheme
40
40
public class Settings : IDisposable
41
41
{
42
42
private static Settings _instance ;
43
- private string filename ;
44
- private FileSystemWatcher watcher ;
45
- private Hashtable map = new Hashtable ( ) ;
46
- private System . Threading . Timer timer ;
47
- private PersistentFileNames pfn ;
43
+ private string _filename ;
44
+ private FileSystemWatcher _watcher ;
45
+ private Hashtable _map = new Hashtable ( ) ;
46
+ private System . Threading . Timer _timer ;
47
+ private PersistentFileNames _pfn ;
48
48
49
49
public static string DefaultUpdateLocation = "https://lovettsoftwarestorage.blob.core.windows.net/downloads/XmlNotepad/Updates.xml" ;
50
50
@@ -103,10 +103,10 @@ public static Settings Instance
103
103
/// </summary>
104
104
public void StopWatchingFileChanges ( )
105
105
{
106
- if ( this . watcher != null )
106
+ if ( this . _watcher != null )
107
107
{
108
- this . watcher . Dispose ( ) ;
109
- this . watcher = null ;
108
+ this . _watcher . Dispose ( ) ;
109
+ this . _watcher = null ;
110
110
}
111
111
}
112
112
@@ -135,12 +135,12 @@ public void OnChanged(string name)
135
135
/// <returns>The setting value or null if not found.</returns>
136
136
public object this [ string name ]
137
137
{
138
- get { return this . map [ name ] ; }
138
+ get { return this . _map [ name ] ; }
139
139
set
140
140
{
141
- if ( this . map [ name ] != value )
141
+ if ( this . _map [ name ] != value )
142
142
{
143
- this . map [ name ] = value ;
143
+ this . _map [ name ] = value ;
144
144
OnChanged ( name ) ;
145
145
}
146
146
}
@@ -151,7 +151,7 @@ public object this[string name]
151
151
/// </summary>
152
152
public void Reload ( )
153
153
{
154
- Load ( this . filename ) ;
154
+ Load ( this . _filename ) ;
155
155
}
156
156
157
157
/// <summary>
@@ -161,7 +161,7 @@ public void Reload()
161
161
/// <param name="filename">XmlNotepad settings xml file.</param>
162
162
public void Load ( string filename )
163
163
{
164
- pfn = new PersistentFileNames ( Settings . Instance . StartupPath ) ;
164
+ _pfn = new PersistentFileNames ( Settings . Instance . StartupPath ) ;
165
165
166
166
// we don't use the serializer because it's too slow to fire up.
167
167
try
@@ -175,7 +175,7 @@ public void Load(string filename)
175
175
if ( r . NodeType == XmlNodeType . Element )
176
176
{
177
177
string name = r . Name ;
178
- object o = map [ name ] ;
178
+ object o = _map [ name ] ;
179
179
if ( o != null )
180
180
{
181
181
object value = null ;
@@ -219,20 +219,20 @@ public void Load(string filename)
219
219
220
220
public string FileName
221
221
{
222
- get { return this . filename ; }
222
+ get { return this . _filename ; }
223
223
set
224
224
{
225
- if ( this . filename != value )
225
+ if ( this . _filename != value )
226
226
{
227
- this . filename = value ;
227
+ this . _filename = value ;
228
228
229
229
StopWatchingFileChanges ( ) ;
230
230
231
- this . watcher = new FileSystemWatcher ( Path . GetDirectoryName ( filename ) ,
232
- Path . GetFileName ( filename ) ) ;
231
+ this . _watcher = new FileSystemWatcher ( Path . GetDirectoryName ( _filename ) ,
232
+ Path . GetFileName ( _filename ) ) ;
233
233
234
- this . watcher . Changed += new FileSystemEventHandler ( watcher_Changed ) ;
235
- this . watcher . EnableRaisingEvents = true ;
234
+ this . _watcher . Changed += new FileSystemEventHandler ( watcher_Changed ) ;
235
+ this . _watcher . EnableRaisingEvents = true ;
236
236
}
237
237
}
238
238
}
@@ -241,7 +241,7 @@ string ConvertToString(object value)
241
241
{
242
242
if ( value is Uri )
243
243
{
244
- return pfn . GetPersistentFileName ( ( Uri ) value ) ;
244
+ return _pfn . GetPersistentFileName ( ( Uri ) value ) ;
245
245
}
246
246
else if ( value is string )
247
247
{
@@ -263,7 +263,7 @@ object ConvertToType(string value, Type type)
263
263
{
264
264
if ( type == typeof ( Uri ) )
265
265
{
266
- return pfn . GetAbsoluteFilename ( value ) ;
266
+ return _pfn . GetAbsoluteFileName ( value ) ;
267
267
}
268
268
else if ( type == typeof ( string ) )
269
269
{
@@ -294,9 +294,9 @@ public void Save(string filename)
294
294
{
295
295
w . Formatting = Formatting . Indented ;
296
296
w . WriteStartElement ( "Settings" ) ;
297
- foreach ( string key in map . Keys )
297
+ foreach ( string key in _map . Keys )
298
298
{
299
- object value = map [ key ] ;
299
+ object value = _map [ key ] ;
300
300
if ( value != null )
301
301
{
302
302
if ( value is Hashtable )
@@ -418,19 +418,19 @@ private void watcher_Changed(object sender, FileSystemEventArgs e)
418
418
// events and we don't want to have lots of dialogs popping up asking the
419
419
// user to reload settings, so we insert a delay to let the events
420
420
// settle down, then we tell the hosting app that the settings have changed.
421
- if ( e . ChangeType == WatcherChangeTypes . Changed && this . timer == null )
421
+ if ( e . ChangeType == WatcherChangeTypes . Changed && this . _timer == null )
422
422
{
423
- this . timer = new System . Threading . Timer ( new TimerCallback ( OnDelay ) , this , 2000 , Timeout . Infinite ) ;
423
+ this . _timer = new System . Threading . Timer ( new TimerCallback ( OnDelay ) , this , 2000 , Timeout . Infinite ) ;
424
424
}
425
425
}
426
426
427
427
void OnDelay ( object state )
428
428
{
429
429
OnChanged ( "File" ) ;
430
- if ( this . timer != null )
430
+ if ( this . _timer != null )
431
431
{
432
- this . timer . Dispose ( ) ;
433
- this . timer = null ;
432
+ this . _timer . Dispose ( ) ;
433
+ this . _timer = null ;
434
434
}
435
435
}
436
436
@@ -447,11 +447,11 @@ public void Dispose()
447
447
protected virtual void Dispose ( bool disposing )
448
448
{
449
449
this . StopWatchingFileChanges ( ) ;
450
- if ( this . timer != null )
450
+ if ( this . _timer != null )
451
451
{
452
- this . timer . Dispose ( ) ;
452
+ this . _timer . Dispose ( ) ;
453
453
}
454
- this . timer = null ;
454
+ this . _timer = null ;
455
455
GC . SuppressFinalize ( this ) ;
456
456
}
457
457
@@ -461,31 +461,19 @@ protected virtual void Dispose(bool disposing)
461
461
public bool GetBoolean ( string settingName , bool defaultValue = false )
462
462
{
463
463
object settingValue = this [ settingName ] ;
464
- if ( settingValue is bool )
465
- {
466
- return ( bool ) settingValue ;
467
- }
468
- return defaultValue ;
464
+ return settingValue is bool value ? value : defaultValue ;
469
465
}
470
466
471
467
public int GetInteger ( string settingName , int defaultValue = 0 )
472
468
{
473
469
object settingValue = this [ settingName ] ;
474
- if ( settingValue is int )
475
- {
476
- return ( int ) settingValue ;
477
- }
478
- return defaultValue ;
470
+ return settingValue is int value ? value : defaultValue ;
479
471
}
480
472
481
473
public string GetString ( string settingName , string defaultValue = "" )
482
474
{
483
475
object settingValue = this [ settingName ] ;
484
- if ( settingValue != null )
485
- {
486
- return settingValue . ToString ( ) ;
487
- }
488
- return defaultValue ;
476
+ return settingValue != null ? settingValue . ToString ( ) : defaultValue ;
489
477
}
490
478
491
479
public Hashtable GetDefaultColors ( ColorTheme theme )
@@ -551,14 +539,14 @@ public void AddDefaultColors(string name, ColorTheme theme)
551
539
/// </summary>
552
540
class PersistentFileNames
553
541
{
554
- Hashtable variables = new Hashtable ( ) ;
542
+ private readonly Hashtable _variables = new Hashtable ( ) ;
555
543
556
544
public PersistentFileNames ( string startupPath )
557
545
{
558
- variables [ "StartupPath" ] = startupPath ;
559
- variables [ "ProgramFiles" ] = Environment . GetEnvironmentVariable ( "ProgramFiles" ) ;
560
- variables [ "UserProfile" ] = Environment . GetEnvironmentVariable ( "UserProfile" ) ;
561
- variables [ "SystemRoot" ] = Environment . GetEnvironmentVariable ( "SystemRoot" ) ;
546
+ _variables [ "StartupPath" ] = startupPath ;
547
+ _variables [ "ProgramFiles" ] = Environment . GetEnvironmentVariable ( "ProgramFiles" ) ;
548
+ _variables [ "UserProfile" ] = Environment . GetEnvironmentVariable ( "UserProfile" ) ;
549
+ _variables [ "SystemRoot" ] = Environment . GetEnvironmentVariable ( "SystemRoot" ) ;
562
550
}
563
551
564
552
public string GetPersistentFileName ( Uri uri )
@@ -574,9 +562,9 @@ public string GetPersistentFileName(Uri uri)
574
562
return null ;
575
563
576
564
// replace absolute paths with variables.
577
- foreach ( string key in variables . Keys )
565
+ foreach ( string key in _variables . Keys )
578
566
{
579
- string baseDir = ( string ) variables [ key ] ;
567
+ string baseDir = ( string ) _variables [ key ] ;
580
568
if ( ! baseDir . EndsWith ( Path . DirectorySeparatorChar . ToString ( ) ) )
581
569
baseDir += Path . DirectorySeparatorChar ;
582
570
Uri baseUri = new Uri ( baseDir ) ;
@@ -602,17 +590,17 @@ public string GetPersistentFileName(Uri uri)
602
590
return result ;
603
591
}
604
592
605
- public Uri GetAbsoluteFilename ( string filename )
593
+ public Uri GetAbsoluteFileName ( string filename )
606
594
{
607
595
try
608
596
{
609
597
// replace variables with absolute paths.
610
- foreach ( string key in variables . Keys )
598
+ foreach ( string key in _variables . Keys )
611
599
{
612
600
string var = "%" + key + "%" ;
613
601
if ( filename . StartsWith ( var , StringComparison . CurrentCultureIgnoreCase ) )
614
602
{
615
- string baseDir = ( string ) variables [ key ] ;
603
+ string baseDir = ( string ) _variables [ key ] ;
616
604
string relPath = filename . Substring ( var . Length ) ;
617
605
if ( ! baseDir . EndsWith ( Path . DirectorySeparatorChar . ToString ( ) ) )
618
606
baseDir += Path . DirectorySeparatorChar ;
0 commit comments