ExpressionBuilder.GetCodeExpression 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在衍生類別中覆寫時,傳回用來在頁面執行期間取得評估的運算式之程式碼。
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 傳回轉換作業。