Επεξεργασία

Κοινή χρήση μέσω


ExpressionBuilder.GetCodeExpression Method

Definition

When overridden in a derived class, returns code that is used during page execution to obtain the evaluated expression.

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

Parameters

entry
BoundPropertyEntry

The object that represents information about the property bound to by the expression.

parsedData
Object

The object containing parsed data as returned by ParseExpression(String, Type, ExpressionBuilderContext).

context
ExpressionBuilderContext

Contextual information for the evaluation of the expression.

Returns

A CodeExpression that is used for property assignment.

Examples

The following code example demonstrates how to return a CodeExpression object by overriding the GetCodeExpression method.

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

Remarks

Classes that inherit from the ExpressionBuilder class must implement the GetCodeExpression abstract method.

Notes to Implementers

If you implement a custom expression builder, you must perform the proper type casting for the control property and return the cast operation in the CodeExpression object.

Applies to