本文整理匯總了C#中System.Web.Compilation.ExpressionBuilder類的典型用法代碼示例。如果您正苦於以下問題:C# ExpressionBuilder類的具體用法?C# ExpressionBuilder怎麽用?C# ExpressionBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ExpressionBuilder類屬於System.Web.Compilation命名空間,在下文中一共展示了ExpressionBuilder類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetEvalData
//引入命名空間
using System;
using System.CodeDom;
using System.Web.UI;
using System.ComponentModel;
using System.Web.Compilation;
using System.Web.UI.Design;
// Apply ExpressionEditorAttributes to allow the
// expression to appear in the designer.
[ExpressionPrefix("MyCustomExpression")]
[ExpressionEditor("MyCustomExpressionEditor")]
public class MyExpressionBuilder : ExpressionBuilder
{
// Create a method that will return the result
// set for the expression argument.
public static object GetEvalData(string expression, Type target, string entry)
{
return expression;
}
public override object EvaluateExpression(object target, BoundPropertyEntry entry,
object parsedData, ExpressionBuilderContext context)
{
return GetEvalData(entry.Expression, target.GetType(), entry.Name);
}
public override CodeExpression GetCodeExpression(BoundPropertyEntry entry,
object parsedData, ExpressionBuilderContext context)
{
Type type1 = entry.DeclaringType;
PropertyDescriptor descriptor1 = TypeDescriptor.GetProperties(type1)[entry.PropertyInfo.Name];
CodeExpression[] expressionArray1 = new CodeExpression[3];
expressionArray1[0] = new CodePrimitiveExpression(entry.Expression.Trim());
expressionArray1[1] = new CodeTypeOfExpression(type1);
expressionArray1[2] = new CodePrimitiveExpression(entry.Name);
return new CodeCastExpression(descriptor1.PropertyType, new CodeMethodInvokeExpression(new
CodeTypeReferenceExpression(base.GetType()), "GetEvalData", expressionArray1));
}
public override bool SupportsEvaluate
{
get { return true; }
}
}