ExpressionPrefixAttribute クラス

定義

式ビルダーで使用するプレフィックス属性を指定します。 このクラスは継承できません。

public ref class ExpressionPrefixAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false)]
public sealed class ExpressionPrefixAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false)>]
type ExpressionPrefixAttribute = class
    inherit Attribute
Public NotInheritable Class ExpressionPrefixAttribute
Inherits Attribute
継承
ExpressionPrefixAttribute
属性

次のコード例は、 クラスの使用方法を ExpressionPrefixAttribute 示しています。 属性は、抽象クラスを実装するカスタム式ビルダーに ExpressionBuilder 適用されます。 この の ExpressionBuilder 実装は、式に渡される評価されたステートメントを返します。 この例を実行するには、最初にカスタム式ビルダーを Web.config ファイルに登録する必要があります。 最初のコード例では、カスタム式ビルダーを Web.config ファイルに登録する方法を示します。

<configuration>  
    <system.web>  
       <compilation>  
          <expressionBuilders>  
              <add expressionPrefix="MyCustomExpression"  
               type="MyCustomExpressionBuilder"/>  
          </expressionBuilders>  
       </compilation>  
    </system.web>  
</configuration>  

2 番目のコード例では、.aspx ファイル内の式を参照する方法を示します。

<asp:Label ID="Label1" runat="server"   
Text="<%$ MyCustomExpression:Hello, world! %>" />  

3 番目のコード例では、 から ExpressionBuilder派生してカスタマイズされた式ビルダーを開発する方法を示します。 このコード例を実行するには、 クラスを App_Code フォルダーに配置する必要があります。

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; }
    }
}
Imports System.CodeDom
Imports System.Web.UI
Imports System.ComponentModel
Imports System.Web.Compilation
Imports System.Web.UI.Design

' Apply ExpressionEditorAttributes to allow the 
' expression to appear in the designer.
<ExpressionPrefix("MyCustomExpression")> _
<ExpressionEditor("MyCustomExpressionEditor")> _
Public Class MyExpressionBuilder
    Inherits ExpressionBuilder
    ' Create a method that will return the result 
    ' set for the expression argument.
    Public Shared Function GetEvalData(ByVal expression As String, _
       ByVal target As Type, ByVal entry As String) As Object
        Return expression
    End Function

    Public Overrides Function EvaluateExpression(ByVal target As Object, _
       ByVal entry As BoundPropertyEntry, ByVal parsedData As Object, _
       ByVal context As ExpressionBuilderContext) As Object
        Return GetEvalData(entry.Expression, target.GetType(), entry.Name)
    End Function

    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

    Public Overrides ReadOnly Property SupportsEvaluate() As Boolean
        Get
            Return True
        End Get
    End Property
End Class

注釈

クラスは ExpressionPrefixAttribute 、デザイン時に、構成ファイルで定義されていない式で使用されます。 オブジェクトに ExpressionPrefix 関連付けられているプレフィックスの名前を取得するには、 プロパティを ExpressionPrefixAttribute 使用します。 式ビルダーは、次の形式のステートメントを検索します。

<%$ [expressionPrefix]:[expressionValue] %>

次に、式ビルダーは、式のプレフィックスに基づいて、プロパティの割り当てのコードを生成します。 パラメーターは expressionPrefix 、構成された式ビルダーを参照します。これは、構成ファイルまたは オブジェクトで ExpressionPrefixAttribute 定義されます。

コンストラクター

ExpressionPrefixAttribute(String)

ExpressionPrefixAttribute クラスの新しいインスタンスを初期化します。

プロパティ

ExpressionPrefix

現在の ExpressionBuilder オブジェクトのプレフィックス値を取得します。

TypeId

派生クラスで実装されると、この Attribute の一意の識別子を取得します。

(継承元 Attribute)

メソッド

Equals(Object)

このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。

(継承元 Attribute)
GetHashCode()

このインスタンスのハッシュ コードを返します。

(継承元 Attribute)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsDefaultAttribute()

派生クラスでオーバーライドされるとき、このインスタンスの値が派生クラスの既定値であるかどうかを示します。

(継承元 Attribute)
Match(Object)

派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。

(継承元 Attribute)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

一連の名前を対応する一連のディスパッチ識別子に割り当てます。

(継承元 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

オブジェクトの型情報を取得します。この情報はインターフェイスの型情報の取得に使用できます。

(継承元 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。

(継承元 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。

(継承元 Attribute)

適用対象

こちらもご覧ください