ExpressionBuilder.GetCodeExpression 方法

定义

在派生类中重写时,返回在页执行过程中用来获取计算出的表达式的代码。

public:
 abstract System::CodeDom::CodeExpression ^ GetCodeExpression(System::Web::UI::BoundPropertyEntry ^ entry, System::Object ^ parsedData, System::Web::Compilation::ExpressionBuilderContext ^ context);
public abstract System.CodeDom.CodeExpression GetCodeExpression (System.Web.UI.BoundPropertyEntry entry, object parsedData, System.Web.Compilation.ExpressionBuilderContext context);
abstract member GetCodeExpression : System.Web.UI.BoundPropertyEntry * obj * System.Web.Compilation.ExpressionBuilderContext -> System.CodeDom.CodeExpression
Public MustOverride Function GetCodeExpression (entry As BoundPropertyEntry, parsedData As Object, context As ExpressionBuilderContext) As CodeExpression

参数

entry
BoundPropertyEntry

表示与被表达式绑定到的属性有关的信息的对象。

parsedData
Object

包含通过分析得到并且由 ParseExpression(String, Type, ExpressionBuilderContext) 返回的数据的对象。

context
ExpressionBuilderContext

表达式计算的上下文信息。

返回

用于为属性赋值的 CodeExpression

示例

下面的代码示例演示如何通过重写 GetCodeExpression 方法返回 CodeExpression 对象。

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 Overrides Function GetCodeExpression(ByVal entry _
   As BoundPropertyEntry, ByVal parsedData As Object, ByVal context _
   As ExpressionBuilderContext) As CodeExpression
    Dim type1 As Type = entry.DeclaringType
    Dim descriptor1 As PropertyDescriptor = _
       TypeDescriptor.GetProperties(type1)(entry.PropertyInfo.Name)
    Dim expressionArray1(2) As CodeExpression
    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 _
       (MyBase.GetType()), "GetEvalData", expressionArray1))
End Function

注解

继承自 类的 ExpressionBuilder 类必须实现 GetCodeExpression 抽象方法。

实施者说明

如果实现自定义表达式生成器,则必须对控件属性执行正确的类型强制转换,并在 对象中 CodeExpression 返回强制转换操作。

适用于