2
2
global using CM = Terminal . Gui . ConfigurationManager ;
3
3
using System . Collections ;
4
4
using System . Diagnostics ;
5
+ using System . Diagnostics . CodeAnalysis ;
5
6
using System . Reflection ;
6
7
using System . Text . Encodings . Web ;
7
8
using System . Text . Json ;
@@ -33,19 +34,19 @@ namespace Terminal.Gui;
33
34
/// Settings are applied using the following precedence (higher precedence settings overwrite lower precedence
34
35
/// settings):
35
36
/// <para>
36
- /// 1. Application configuration found in the users's home directory (<c>~/.tui/appname.config.json</c>) --
37
+ /// 1. Application configuration found in the users' home directory (<c>~/.tui/appname.config.json</c>) --
37
38
/// Highest precedence
38
39
/// </para>
39
40
/// <para>
40
41
/// 2. Application configuration found in the directory the app was launched from (
41
42
/// <c>./.tui/appname.config.json</c>).
42
43
/// </para>
43
- /// <para>3. Application configuration found in the applications's resources (<c>Resources/config.json</c>).</para>
44
+ /// <para>3. Application configuration found in the applications' resources (<c>Resources/config.json</c>).</para>
44
45
/// <para>4. Global configuration found in the user's home directory (<c>~/.tui/config.json</c>).</para>
45
46
/// <para>5. Global configuration found in the directory the app was launched from (<c>./.tui/config.json</c>).</para>
46
47
/// <para>
47
48
/// 6. Global configuration in <c>Terminal.Gui.dll</c>'s resources (<c>Terminal.Gui.Resources.config.json</c>) --
48
- /// Lowest Precidence .
49
+ /// Lowest Precedence .
49
50
/// </para>
50
51
/// </summary>
51
52
public static class ConfigurationManager
@@ -82,8 +83,10 @@ public enum ConfigLocations
82
83
/// <see cref="ConfigurationManager"/> to get and set the property's value.
83
84
/// </summary>
84
85
/// <remarks>Is <see langword="null"/> until <see cref="Initialize"/> is called.</remarks>
86
+ [ SuppressMessage ( "Style" , "IDE1006:Naming Styles" , Justification = "<Pending>" ) ]
85
87
internal static Dictionary < string , ConfigProperty > ? _allConfigProperties ;
86
88
89
+ [ SuppressMessage ( "Style" , "IDE1006:Naming Styles" , Justification = "<Pending>" ) ]
87
90
internal static readonly JsonSerializerOptions _serializerOptions = new ( )
88
91
{
89
92
ReadCommentHandling = JsonCommentHandling . Skip ,
@@ -104,8 +107,10 @@ public enum ConfigLocations
104
107
Encoder = JavaScriptEncoder . UnsafeRelaxedJsonEscaping
105
108
} ;
106
109
107
- internal static StringBuilder jsonErrors = new ( ) ;
110
+ [ SuppressMessage ( "Style" , "IDE1006:Naming Styles" , Justification = "<Pending>" ) ]
111
+ internal static StringBuilder _jsonErrors = new ( ) ;
108
112
113
+ [ SuppressMessage ( "Style" , "IDE1006:Naming Styles" , Justification = "<Pending>" ) ]
109
114
private static readonly string _configFilename = "config.json" ;
110
115
111
116
/// <summary>The backing property for <see cref="Settings"/>.</summary>
@@ -280,7 +285,7 @@ public static void Load (bool reset = false)
280
285
public static void OnApplied ( )
281
286
{
282
287
Debug . WriteLine ( "ConfigurationManager.OnApplied()" ) ;
283
- Applied ? . Invoke ( null , new ConfigurationManagerEventArgs ( ) ) ;
288
+ Applied ? . Invoke ( null , new ( ) ) ;
284
289
285
290
// TODO: Refactor ConfigurationManager to not use an event handler for this.
286
291
// Instead, have it call a method on any class appropriately attributed
@@ -294,18 +299,18 @@ public static void OnApplied ()
294
299
public static void OnUpdated ( )
295
300
{
296
301
Debug . WriteLine ( @"ConfigurationManager.OnApplied()" ) ;
297
- Updated ? . Invoke ( null , new ConfigurationManagerEventArgs ( ) ) ;
302
+ Updated ? . Invoke ( null , new ( ) ) ;
298
303
}
299
304
300
305
/// <summary>Prints any Json deserialization errors that occurred during deserialization to the console.</summary>
301
306
public static void PrintJsonErrors ( )
302
307
{
303
- if ( jsonErrors . Length > 0 )
308
+ if ( _jsonErrors . Length > 0 )
304
309
{
305
310
Console . WriteLine (
306
311
@"Terminal.Gui ConfigurationManager encountered the following errors while deserializing configuration files:"
307
312
) ;
308
- Console . WriteLine ( jsonErrors . ToString ( ) ) ;
313
+ Console . WriteLine ( _jsonErrors . ToString ( ) ) ;
309
314
}
310
315
}
311
316
@@ -326,9 +331,9 @@ public static void Reset ()
326
331
327
332
ClearJsonErrors ( ) ;
328
333
329
- Settings = new SettingsScope ( ) ;
334
+ Settings = new ( ) ;
330
335
ThemeManager . Reset ( ) ;
331
- AppSettings = new AppScope ( ) ;
336
+ AppSettings = new ( ) ;
332
337
333
338
// To enable some unit tests, we only load from resources if the flag is set
334
339
if ( Locations . HasFlag ( ConfigLocations . DefaultOnly ) )
@@ -350,23 +355,20 @@ public static void Reset ()
350
355
internal static void AddJsonError ( string error )
351
356
{
352
357
Debug . WriteLine ( $ "ConfigurationManager: { error } ") ;
353
- jsonErrors . AppendLine ( error ) ;
358
+ _jsonErrors . AppendLine ( error ) ;
354
359
}
355
360
356
361
/// <summary>
357
362
/// System.Text.Json does not support copying a deserialized object to an existing instance. To work around this,
358
- /// we implement a 'deep, memberwise copy' method.
363
+ /// we implement a 'deep, member-wise copy' method.
359
364
/// </summary>
360
365
/// <remarks>TOOD: When System.Text.Json implements `PopulateObject` revisit https://github.com/dotnet/corefx/issues/37627</remarks>
361
366
/// <param name="source"></param>
362
367
/// <param name="destination"></param>
363
368
/// <returns><paramref name="destination"/> updated from <paramref name="source"/></returns>
364
- internal static object ? DeepMemberwiseCopy ( object ? source , object ? destination )
369
+ internal static object ? DeepMemberWiseCopy ( object ? source , object ? destination )
365
370
{
366
- if ( destination is null )
367
- {
368
- throw new ArgumentNullException ( nameof ( destination ) ) ;
369
- }
371
+ ArgumentNullException . ThrowIfNull ( destination ) ;
370
372
371
373
if ( source is null )
372
374
{
@@ -406,7 +408,7 @@ internal static void AddJsonError (string error)
406
408
if ( ( ( IDictionary ) destination ) . Contains ( srcKey ) )
407
409
{
408
410
( ( IDictionary ) destination ) [ srcKey ] =
409
- DeepMemberwiseCopy ( ( ( IDictionary ) source ) [ srcKey ] , ( ( IDictionary ) destination ) [ srcKey ] ) ;
411
+ DeepMemberWiseCopy ( ( ( IDictionary ) source ) [ srcKey ] , ( ( IDictionary ) destination ) [ srcKey ] ) ;
410
412
}
411
413
else
412
414
{
@@ -438,7 +440,7 @@ where destProp.CanWrite
438
440
if ( destVal is { } )
439
441
{
440
442
// Recurse
441
- destProp . SetValue ( destination , DeepMemberwiseCopy ( sourceVal , destVal ) ) ;
443
+ destProp . SetValue ( destination , DeepMemberWiseCopy ( sourceVal , destVal ) ) ;
442
444
}
443
445
else
444
446
{
@@ -478,7 +480,7 @@ internal static void GetHardCodedDefaults ()
478
480
throw new InvalidOperationException ( "Initialize must be called first." ) ;
479
481
}
480
482
481
- Settings = new SettingsScope ( ) ;
483
+ Settings = new ( ) ;
482
484
ThemeManager . GetHardCodedDefaults ( ) ;
483
485
AppSettings ? . RetrieveValues ( ) ;
484
486
@@ -494,7 +496,7 @@ internal static void GetHardCodedDefaults ()
494
496
/// </summary>
495
497
internal static void Initialize ( )
496
498
{
497
- _allConfigProperties = new Dictionary < string , ConfigProperty > ( ) ;
499
+ _allConfigProperties = new ( ) ;
498
500
_settings = null ;
499
501
500
502
Dictionary < string , Type > classesWithConfigProps = new ( StringComparer . InvariantCultureIgnoreCase ) ;
@@ -549,18 +551,18 @@ from p in enumerable
549
551
scp . OmitClassName
550
552
? ConfigProperty . GetJsonPropertyName ( p )
551
553
: $ "{ p . DeclaringType ? . Name } .{ p . Name } ",
552
- new ConfigProperty { PropertyInfo = p , PropertyValue = null }
554
+ new ( ) { PropertyInfo = p , PropertyValue = null }
553
555
) ;
554
556
}
555
557
else
556
558
{
557
- throw new Exception (
558
- $ "Property {
559
- p . Name
560
- } in class {
561
- p . DeclaringType ? . Name
562
- } is not static. All SerializableConfigurationProperty properties must be static."
563
- ) ;
559
+ throw new (
560
+ $ "Property {
561
+ p . Name
562
+ } in class {
563
+ p . DeclaringType ? . Name
564
+ } is not static. All SerializableConfigurationProperty properties must be static."
565
+ ) ;
564
566
}
565
567
}
566
568
}
@@ -576,7 +578,7 @@ from p in enumerable
576
578
577
579
//_allConfigProperties.ToList ().ForEach (x => Debug.WriteLine ($" Property: {x.Key}"));
578
580
579
- AppSettings = new AppScope ( ) ;
581
+ AppSettings = new ( ) ;
580
582
}
581
583
582
584
/// <summary>Creates a JSON document with the configuration specified.</summary>
@@ -602,5 +604,5 @@ internal static Stream ToStream ()
602
604
return stream ;
603
605
}
604
606
605
- private static void ClearJsonErrors ( ) { jsonErrors . Clear ( ) ; }
607
+ private static void ClearJsonErrors ( ) { _jsonErrors . Clear ( ) ; }
606
608
}
0 commit comments