我最终构建了自己的ExpressionBuilder
,它使用内置ResourceExpressionBuilder
来获取底层资源值,然后将其转换为小写:
将基本表达式转换为小写字符串
public class ResourceLowerCase : ResourceExpressionBuilder
{
public override CodeExpression GetCodeExpression(BoundPropertyEntry entry, object parsedData, ExpressionBuilderContext context)
{
CodeExpression getResourceExpression = base.GetCodeExpression(entry, parsedData, context);
CodeMethodInvokeExpression toStringExpression = new CodeMethodInvokeExpression(getResourceExpression, "ToString");
CodeMethodInvokeExpression toLowerExpression = new CodeMethodInvokeExpression(toStringExpression, "ToLower");
return toLowerExpression;
}
}
注册表达式生成器
<system.web>
<expressionBuilders>
<add expressionPrefix="ResourceLowerCase" type="My.Project.Compilation.ResourceLowerCase"/>
</expressionBuilders>
</compilation>
调用表达式生成器
<asp:Literal runat="server" Text="<%$ ResourceLowerCase:Global, MyString %>" />