/// <summary> /// Applies the rules to the target definition. /// </summary> /// <param name="context">The working context.</param> /// <param name="target">The target definition.</param> /// <param name="rules">The rules.</param> /// <param name="baseSettings">The base settings.</param> protected void ApplyRules(ConfuserContext context, ISDnlibDef target, Rules rules, ProtectionSettings baseSettings = null) { var ret = baseSettings == null ? new ProtectionSettings() : new ProtectionSettings(baseSettings); foreach (var i in rules) { if (!(bool)i.Value.Evaluate(target)) { continue; } if (!i.Key.Inherit) { ret.Clear(); } FillPreset(i.Key.Preset, ret); foreach (var prot in i.Key) { if (prot.Action == SettingItemAction.Add) { ret[protections[prot.Id]] = new Dictionary <string, string>(prot, StringComparer.OrdinalIgnoreCase); } else { ret.Remove(protections[prot.Id]); } } } ProtectionParameters.SetParameters(context, target, ret); }
public IDisposable Apply(ISDnlibDef target, IEnumerable <ProtectionSettingsInfo> infos) { ProtectionSettings settings; if (this.settings == null) { settings = new ProtectionSettings(); } else { settings = new ProtectionSettings(this.settings); } var infoArray = infos.ToArray(); if (stack.Count > 0) { foreach (var i in stack.Reverse()) { ApplyInfo(target, settings, i.Item2, ApplyInfoType.ParentInfo); } } IDisposable result; if (infoArray.Length != 0) { var originalSettings = this.settings; // the settings that would apply to members ApplyInfo(target, settings, infoArray, ApplyInfoType.CurrentInfoInherits); this.settings = new ProtectionSettings(settings); // the settings that would apply to itself ApplyInfo(target, settings, infoArray, ApplyInfoType.CurrentInfoOnly); stack.Push(Tuple.Create(originalSettings, infoArray)); result = new PopHolder(this); } else { result = null; } ProtectionParameters.SetParameters(context, target, settings); return(result); }