using System; using System.Text.RegularExpressions; using dnlib.DotNet; namespace Confuser.Core.Project.Patterns { /// /// A function that match the full name of the definition with specified RegEx. /// public class MatchFunction : PatternFunction { internal const string FnName = "match"; /// public override string Name { get { return FnName; } } /// public override int ArgumentCount { get { return 1; } } /// public override object Evaluate(IDnlibDef definition) { string regex = Arguments[0].Evaluate(definition).ToString(); return Regex.IsMatch(definition.FullName, regex); } } /// /// A function that match the name of the definition with specified RegEx. /// public class MatchNameFunction : PatternFunction { internal const string FnName = "match-name"; /// public override string Name { get { return FnName; } } /// public override int ArgumentCount { get { return 1; } } /// public override object Evaluate(IDnlibDef definition) { string regex = Arguments[0].Evaluate(definition).ToString(); return Regex.IsMatch(definition.Name, regex); } } /// /// A function that match the name of declaring type with specified RegEx. /// public class MatchTypeNameFunction : PatternFunction { internal const string FnName = "match-type-name"; /// public override string Name { get { return FnName; } } /// public override int ArgumentCount { get { return 1; } } /// public override object Evaluate(IDnlibDef definition) { if (definition is TypeDef) { string regex = Arguments[0].Evaluate(definition).ToString(); return Regex.IsMatch(definition.Name, regex); } if (definition is IMemberDef && ((IMemberDef)definition).DeclaringType != null) { string regex = Arguments[0].Evaluate(definition).ToString(); return Regex.IsMatch(((IMemberDef)definition).DeclaringType.Name, regex); } return false; } } }