/// <exception cref="NotSupportedException"> /// <typeparamref name="TObject" />is a dictionary. Code protection for dictionary types are /// not yet supported. /// </exception> protected sealed override void ChangeProtectionMode( IProtectionChangeContext <SafeObjectProtectionMode> context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } switch (context.NewValue) { case SafeObjectProtectionMode.StateAndCode: if (IsDictionary(typeof(TObject))) { throw new NotSupportedException( $"{typeof(TObject).Name} is a dictionary. Code protection for dictionary types are not yet supported."); } _injectionDetector.ScanCode = true; _injectionDetector.ScanState = true; if (context.OldValue != SafeObjectProtectionMode.JustState) { VerifyChangesInternal(null, false); } break; case SafeObjectProtectionMode.JustState: _injectionDetector.ScanCode = false; _injectionDetector.ScanState = true; if (context.OldValue != SafeObjectProtectionMode.StateAndCode) { VerifyChangesInternal(null, false); } break; case SafeObjectProtectionMode.JustCode: if (IsDictionary(typeof(TObject))) { throw new NotSupportedException( $"{typeof(TObject).Name} is a dictionary. Code protection for dictionaries are not yet supported."); } _injectionDetector.ScanCode = true; _injectionDetector.ScanState = false; break; case SafeObjectProtectionMode.NoProtection: _injectionDetector.ScanCode = false; _injectionDetector.ScanState = false; break; default: throw new UnexpectedEnumValueException <SafeObjectProtectionMode>(context.NewValue); } }
/// <summary> /// Changes the protection mode of the inner dictionary and its values. /// </summary> protected sealed override void ChangeProtectionMode( IProtectionChangeContext <SafeContainerProtectionMode> context) { Dictionary <string, IInstanceProvider> newDictionary = null; if (_typeInstancesSafe != null) { var innerInstanceProtection = GetInnerInstanceProtectionMode(context.NewValue); newDictionary = _typeInstancesSafe.Object; newDictionary.Values.ForEach(instance => instance.SetProtectionMode(innerInstanceProtection)); _typeInstancesSafe.Dispose(); } //re-create inner safe object _typeInstancesSafe = CreateInnerDictionary(context.NewValue, AlertChannel, newDictionary); }
protected sealed override void ChangeProtectionMode(IProtectionChangeContext <InstanceProtectionMode> context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } switch (context.NewValue) { case InstanceProtectionMode.StateAndCode: _injectionDetector.ScanCode = true; _injectionDetector.ScanState = this.CanProtectState; if (!_isFirstTime && context.OldValue != InstanceProtectionMode.JustState) { VerifyInstanceInternal(GetInstance()); } break; case InstanceProtectionMode.JustCode: _injectionDetector.ScanCode = true; _injectionDetector.ScanState = false; break; case InstanceProtectionMode.JustState: _injectionDetector.ScanCode = false; _injectionDetector.ScanState = this.CanProtectState; if (!_isFirstTime && context.OldValue != InstanceProtectionMode.StateAndCode) { VerifyInstanceInternal(GetInstance()); } break; case InstanceProtectionMode.NoProtection: _injectionDetector.ScanCode = false; _injectionDetector.ScanState = false; break; default: throw new UnexpectedEnumValueException <InstanceProtectionMode>(context.NewValue); } }
/// <summary> /// Must be overridden with a logic while switching happens. /// </summary> protected abstract void ChangeProtectionMode(IProtectionChangeContext <TProtectionLevel> context);