File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,12 @@ public Categories()
22
22
Read ( ) ;
23
23
}
24
24
25
- private void Read ( string filename = null )
25
+ private void Read ( )
26
26
{
27
27
string categoriesJson ;
28
28
try
29
29
{
30
- if ( string . IsNullOrEmpty ( filename ) ) filename = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) + Path . DirectorySeparatorChar + AppName + Path . DirectorySeparatorChar + AppSettingsFileName ;
30
+ string filename = Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) + Path . DirectorySeparatorChar + AppName + Path . DirectorySeparatorChar + AppSettingsFileName ;
31
31
categoriesJson = File . ReadAllText ( filename ) ;
32
32
}
33
33
catch ( Exception ex )
@@ -40,7 +40,15 @@ private void Read(string filename = null)
40
40
}
41
41
throw ;
42
42
}
43
- MyCategoryList = JsonSerializer . Deserialize < BindingList < MyCategory > > ( categoriesJson , new JsonSerializerOptions { IncludeFields = true } ) ;
43
+ try
44
+ {
45
+ MyCategoryList = JsonSerializer . Deserialize < BindingList < MyCategory > > ( categoriesJson , new JsonSerializerOptions { IncludeFields = true } ) ;
46
+ }
47
+ catch
48
+ {
49
+ MyCategoryList . Add ( new MyCategory ( "Category 1" , "" ) ) ;
50
+ MyCategoryList . Add ( new MyCategory ( "Category 2" , "" ) ) ;
51
+ }
44
52
}
45
53
46
54
public void Write ( string filename = null )
You can’t perform that action at this time.
0 commit comments