Skip to content

Commit 4fbdb3a

Browse files
author
Kapil Borle
committed
Add extension method to get named attribute arg value
1 parent a0a84c1 commit 4fbdb3a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Engine/Extensions.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,39 @@ public static NamedAttributeArgumentAst GetSupportsShouldProcessAst(this Attribu
9494

9595
return null;
9696
}
97+
98+
public static bool IsTrue(this NamedAttributeArgumentAst attrAst, out ExpressionAst argumentAst)
99+
{
100+
argumentAst = null;
101+
if (attrAst.ExpressionOmitted)
102+
{
103+
return true;
104+
}
105+
106+
var varExpAst = attrAst.Argument as VariableExpressionAst;
107+
argumentAst = attrAst.Argument;
108+
if (varExpAst == null)
109+
{
110+
var constExpAst = attrAst.Argument as ConstantExpressionAst;
111+
if (constExpAst == null)
112+
{
113+
return false;
114+
}
115+
116+
bool constExpVal;
117+
if (LanguagePrimitives.TryConvertTo(constExpAst.Value, out constExpVal))
118+
{
119+
return constExpVal;
120+
}
121+
}
122+
else
123+
{
124+
return varExpAst.VariablePath.UserPath.Equals(
125+
bool.TrueString,
126+
StringComparison.OrdinalIgnoreCase);
127+
}
128+
129+
return false;
130+
}
97131
}
98132
}

0 commit comments

Comments
 (0)