Exemple #1
0
 public JsonSettingsAutosaveInterceptor(JsonSettings settings)
 {
     _settings = settings;
     _settings.Modulation.Attach(_module = new AutosaveModule());
     //populate information
     _monitoredProperties = new HashSet <string>(_settings.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)
                                                 .Where(p => p.GetSetMethod()?.IsVirtual == true &&
                                                        p.GetCustomAttribute <JsonIgnoreAttribute>(true) == null && p.GetCustomAttribute <IgnoreAutosaveAttribute>(true) == null &&
                                                        AutosaveModule._frameworkParameters.All(f => f != p.Name))
                                                 .Select(prop => prop.Name));
 }
        public static ISettings EnableIAutosave <ISettings>(this JsonSettings settings) where ISettings : class
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }
            _generator = _generator ?? new ProxyGenerator();

            if (!(settings is ISettings))
            {
                throw new InvalidCastException($"Settings class '{settings.GetType().FullName}' does not implement interface '{typeof(ISettings).FullName}'");
            }

            return(_generator.CreateInterfaceProxyWithTarget <ISettings>((ISettings)(object)settings, new JsonSettingsInterceptor(settings)));
        }