11using CarinaStudio . Collections ;
22using System ;
33using System . Collections . Generic ;
4+ using System . Diagnostics . CodeAnalysis ;
45using System . IO ;
56using System . Linq ;
67using System . Reflection ;
@@ -18,8 +19,8 @@ public abstract class PersistentSettings : ISettings
1819 readonly object eventLock = new object ( ) ;
1920 DateTime lastModifiedTime = DateTime . Now ;
2021 readonly ISettingsSerializer serializer ;
21- volatile EventHandler < SettingChangedEventArgs > ? settingChanged ;
22- volatile EventHandler < SettingChangingEventArgs > ? settingChanging ;
22+ EventHandler < SettingChangedEventArgs > ? settingChanged ;
23+ EventHandler < SettingChangingEventArgs > ? settingChanging ;
2324 readonly Dictionary < SettingKey , object > values = new Dictionary < SettingKey , object > ( ) ;
2425
2526
@@ -70,7 +71,7 @@ protected PersistentSettings(ISettings template, ISettingsSerializer serializer)
7071 /// <summary>
7172 /// Get all setting keys.
7273 /// </summary>
73- public IEnumerable < SettingKey > Keys { get => this . values . Lock ( ( it ) => it . Keys . ToArray ( ) ) ; }
74+ public IEnumerable < SettingKey > Keys => this . values . Lock ( ( it ) => it . Keys . ToArray ( ) ) ;
7475
7576
7677 /// <summary>
@@ -223,6 +224,7 @@ public void Save(string fileName)
223224 if ( File . Exists ( fileName ) )
224225 File . Copy ( fileName , fileName + ".backup" , true ) ;
225226 }
227+ // ReSharper disable once EmptyGeneralCatchClause
226228 catch
227229 { }
228230
@@ -291,7 +293,7 @@ public void SetValue(SettingKey key, object value)
291293 // check value
292294 if ( value == null )
293295 throw new ArgumentNullException ( nameof ( value ) ) ;
294- if ( ! key . ValueType . IsAssignableFrom ( value . GetType ( ) ) )
296+ if ( ! key . ValueType . IsInstanceOfType ( value ) )
295297 throw new ArgumentException ( $ "Value { value } is not { key . ValueType . Name } .") ;
296298
297299 // check previous value
@@ -426,7 +428,7 @@ public SettingKey(string name, Type valueType, object defaultValue)
426428 {
427429 if ( defaultValue == null )
428430 throw new ArgumentNullException ( nameof ( defaultValue ) ) ;
429- if ( ! valueType . IsAssignableFrom ( defaultValue . GetType ( ) ) )
431+ if ( ! valueType . IsInstanceOfType ( defaultValue ) )
430432 throw new ArgumentException ( $ "Default value { defaultValue } is not { valueType . Name } .") ;
431433 this . DefaultValue = defaultValue ;
432434 this . Name = name ;
@@ -444,7 +446,7 @@ public SettingKey(string name, Type valueType, object defaultValue)
444446 /// Get all public <see cref="SettingKey"/> defined by given type.
445447 /// </summary>
446448 /// <returns>List of public <see cref="SettingKey"/>.</returns>
447- public static IList < SettingKey > GetDefinedKeys < T > ( )
449+ public static IList < SettingKey > GetDefinedKeys < [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicFields ) ] T > ( )
448450 {
449451 var keys = new List < SettingKey > ( ) ;
450452 foreach ( var fieldInfo in typeof ( T ) . GetFields ( BindingFlags . Public | BindingFlags . Static ) )
0 commit comments