public bool CanRename(object obj) { if (obj is IDnlibDef) { if (analyze == null) analyze = context.Pipeline.FindPhase<AnalyzePhase>(); var prot = (NameProtection)analyze.Parent; ProtectionSettings parameters = ProtectionParameters.GetParameters(context, (IDnlibDef)obj); if (parameters == null || !parameters.ContainsKey(prot)) return false; return context.Annotations.Get(obj, CanRenameKey, true); } return false; }
// Token: 0x0600025A RID: 602 RVA: 0x0001F978 File Offset: 0x0001DB78 public bool CanRename(object obj) { if (obj is IDnlibDef) { if (this.analyze == null) { this.analyze = this.context.Pipeline.FindPhase <AnalyzePhase>(); } NameProtection prot = (NameProtection)this.analyze.Parent; ProtectionSettings parameters = ProtectionParameters.GetParameters(this.context, (IDnlibDef)obj); return(parameters != null && parameters.ContainsKey(prot) && this.context.Annotations.Get <bool>(obj, NameService.CanRenameKey, true)); } return(false); }
public void ParseProtectionString(ProtectionSettings settings, string str) { if (str == null) return; this.str = str; index = 0; var state = ParseState.Init; var buffer = new StringBuilder(); bool protAct = true; string protId = null; var protParams = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); while (state != ParseState.End) { switch (state) { case ParseState.Init: ReadId(buffer); if (buffer.ToString().Equals("preset", StringComparison.OrdinalIgnoreCase)) { if (IsEnd()) throw new ArgumentException("Unexpected end of string in Init state."); Expect('('); buffer.Length = 0; state = ParseState.ReadPreset; } else if (buffer.Length == 0) { if (IsEnd()) throw new ArgumentException("Unexpected end of string in Init state."); state = ParseState.ReadItemName; } else { protAct = true; state = ParseState.ProcessItemName; } break; case ParseState.ReadPreset: if (!ReadId(buffer)) throw new ArgumentException("Unexpected end of string in ReadPreset state."); Expect(')'); var preset = (ProtectionPreset)Enum.Parse(typeof(ProtectionPreset), buffer.ToString(), true); foreach (var item in items.Values.OfType<Protection>().Where(prot => prot.Preset <= preset)) { if (settings != null && !settings.ContainsKey(item)) settings.Add(item, new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)); } buffer.Length = 0; if (IsEnd()) state = ParseState.End; else { Expect(';'); if (IsEnd()) state = ParseState.End; else state = ParseState.ReadItemName; } break; case ParseState.ReadItemName: protAct = true; if (Peek() == '+') { protAct = true; Next(); } else if (Peek() == '-') { protAct = false; Next(); } ReadId(buffer); state = ParseState.ProcessItemName; break; case ParseState.ProcessItemName: protId = buffer.ToString(); buffer.Length = 0; if (IsEnd() || Peek() == ';') state = ParseState.EndItem; else if (Peek() == '(') { if (!protAct) throw new ArgumentException("No parameters is allowed when removing protection."); Next(); state = ParseState.ReadParam; } else throw new ArgumentException("Unexpected character in ProcessItemName state at " + index + "."); break; case ParseState.ReadParam: string paramName, paramValue; if (!ReadId(buffer)) throw new ArgumentException("Unexpected end of string in ReadParam state."); paramName = buffer.ToString(); buffer.Length = 0; Expect('='); if (!(Peek() == '\'' ? ReadString(buffer) : ReadId(buffer))) throw new ArgumentException("Unexpected end of string in ReadParam state."); paramValue = buffer.ToString(); buffer.Length = 0; protParams.Add(paramName, paramValue); if (Peek() == ',') { Next(); state = ParseState.ReadParam; } else if (Peek() == ')') { Next(); state = ParseState.EndItem; } else throw new ArgumentException("Unexpected character in ReadParam state at " + index + "."); break; case ParseState.EndItem: if (settings != null) { if (protAct) { settings[(Protection)items[protId]] = protParams; } else settings.Remove((Protection)items[protId]); } protParams = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); if (IsEnd()) state = ParseState.End; else { Expect(';'); if (IsEnd()) state = ParseState.End; else state = ParseState.ReadItemName; } break; } } }
/// <summary> /// Fills the protection settings with the specified preset. /// </summary> /// <param name="preset">The preset.</param> /// <param name="settings">The settings.</param> void FillPreset(ProtectionPreset preset, ProtectionSettings settings) { foreach (Protection prot in protections.Values) if (prot.Preset != ProtectionPreset.None && prot.Preset <= preset && !settings.ContainsKey(prot)) settings.Add(prot, new Dictionary<string, string>()); }
public void ParseProtectionString(ProtectionSettings settings, string str) { if (str == null) { return; } this.str = str; index = 0; var state = ParseState.Init; var buffer = new StringBuilder(); bool protAct = true; string protId = null; var protParams = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); while (state != ParseState.End) { switch (state) { case ParseState.Init: ReadId(buffer); if (buffer.ToString().Equals("preset", StringComparison.OrdinalIgnoreCase)) { if (IsEnd()) { throw new ArgumentException("Unexpected end of string in Init state."); } Expect('('); buffer.Length = 0; state = ParseState.ReadPreset; } else if (buffer.Length == 0) { if (IsEnd()) { throw new ArgumentException("Unexpected end of string in Init state."); } state = ParseState.ReadItemName; } else { protAct = true; state = ParseState.ProcessItemName; } break; case ParseState.ReadPreset: if (!ReadId(buffer)) { throw new ArgumentException("Unexpected end of string in ReadPreset state."); } Expect(')'); var preset = (ProtectionPreset)Enum.Parse(typeof(ProtectionPreset), buffer.ToString(), true); foreach (var item in items.Values.OfType <Protection>().Where(prot => prot.Preset <= preset)) { if (!settings.ContainsKey(item)) { settings.Add(item, new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase)); } } buffer.Length = 0; if (IsEnd()) { state = ParseState.End; } else { Expect(';'); if (IsEnd()) { state = ParseState.End; } else { state = ParseState.ReadItemName; } } break; case ParseState.ReadItemName: protAct = true; if (Peek() == '+') { protAct = true; Next(); } else if (Peek() == '-') { protAct = false; Next(); } ReadId(buffer); state = ParseState.ProcessItemName; break; case ParseState.ProcessItemName: protId = buffer.ToString(); buffer.Length = 0; if (IsEnd() || Peek() == ';') { state = ParseState.EndItem; } else if (Peek() == '(') { if (!protAct) { throw new ArgumentException("No parameters is allowed when removing protection."); } Next(); state = ParseState.ReadParam; } else { throw new ArgumentException("Unexpected character in ProcessItemName state at " + index + "."); } break; case ParseState.ReadParam: string paramName, paramValue; if (!ReadId(buffer)) { throw new ArgumentException("Unexpected end of string in ReadParam state."); } paramName = buffer.ToString(); buffer.Length = 0; Expect('='); if (!ReadId(buffer)) { throw new ArgumentException("Unexpected end of string in ReadParam state."); } paramValue = buffer.ToString(); buffer.Length = 0; protParams.Add(paramName, paramValue); if (Peek() == ',') { Next(); state = ParseState.ReadParam; } else if (Peek() == ')') { Next(); state = ParseState.EndItem; } else { throw new ArgumentException("Unexpected character in ReadParam state at " + index + "."); } break; case ParseState.EndItem: if (protAct) { settings[(Protection)items[protId]] = protParams; protParams = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); } else { settings.Remove((Protection)items[protId]); } if (IsEnd()) { state = ParseState.End; } else { Expect(';'); if (IsEnd()) { state = ParseState.End; } else { state = ParseState.ReadItemName; } } break; } } }