Skip to content
This repository has been archived by the owner on Jan 27, 2019. It is now read-only.

Commit

Permalink
Add has-attr pattern function
Browse files Browse the repository at this point in the history
  • Loading branch information
yck1509 committed Dec 6, 2015
1 parent bba1c46 commit bf2368f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions Confuser.Core/Confuser.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<Compile Include="Project\InvalidPatternException.cs" />
<Compile Include="Project\PatternParser.cs" />
<Compile Include="Project\Patterns\AndOperator.cs" />
<Compile Include="Project\Patterns\HasAttrFunction.cs" />
<Compile Include="Project\Patterns\IsTypeFunction.cs" />
<Compile Include="Project\Patterns\InheritsFunction.cs" />
<Compile Include="Project\Patterns\IsPublicFunction.cs" />
Expand Down
1 change: 1 addition & 0 deletions Confuser.Core/Project/PatternParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static PatternParser() {
fns.Add(IsPublicFunction.FnName, () => new IsPublicFunction());
fns.Add(InheritsFunction.FnName, () => new InheritsFunction());
fns.Add(IsTypeFunction.FnName, () => new IsTypeFunction());
fns.Add(HasAttrFunction.FnName, () => new HasAttrFunction());

ops = new Dictionary<string, Func<PatternOperator>>(StringComparer.OrdinalIgnoreCase);
ops.Add(AndOperator.OpName, () => new AndOperator());
Expand Down
27 changes: 27 additions & 0 deletions Confuser.Core/Project/Patterns/HasAttrFunction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using dnlib.DotNet;

namespace Confuser.Core.Project.Patterns {
/// <summary>
/// A function that indicate whether the item has the given custom attribute.
/// </summary>
public class HasAttrFunction : PatternFunction {
internal const string FnName = "has-attr";

/// <inheritdoc />
public override string Name {
get { return FnName; }
}

/// <inheritdoc />
public override int ArgumentCount {
get { return 1; }
}

/// <inheritdoc />
public override object Evaluate(IDnlibDef definition) {
string attrName = Arguments[0].Evaluate(definition).ToString();
return definition.CustomAttributes.IsDefined(attrName);
}
}
}

0 comments on commit bf2368f

Please sign in to comment.