ExpressionPrefixAttributeとは? わかりやすく解説

ExpressionPrefixAttribute クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

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

名前空間: System.Web.Compilation
アセンブリ: System.Web (system.web.dll 内)
構文構文

<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple:=False)> _
Public NotInheritable Class
 ExpressionPrefixAttribute
    Inherits Attribute
Dim instance As ExpressionPrefixAttribute
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false)]
 
public sealed class ExpressionPrefixAttribute
 : Attribute
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple=false)]
 
public ref class ExpressionPrefixAttribute
 sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false)
 */ 
public final class ExpressionPrefixAttribute
 extends Attribute
AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false)
 
public final class ExpressionPrefixAttribute
 extends Attribute
解説解説

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

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

次に式ビルダは、式のプレフィックスに基づいて、プロパティを割り当てるためのコードを生成します。expressionPrefix パラメータは、構成済みの式ビルダを参照します。構成済みの式ビルダは、構成ファイルまたは 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 フォルダに配置する必要があります。

Imports System
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
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;
 }
    }
}
継承階層継承階層
System.Object
   System.Attribute
    System.Web.Compilation.ExpressionPrefixAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ExpressionPrefixAttribute メンバ
System.Web.Compilation 名前空間
ExpressionEditor
ExpressionEditorSheet
AppSettingsExpressionEditor
ExpressionBuilder クラス
ExpressionPrefix

ExpressionPrefixAttribute コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

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

名前空間: System.Web.Compilation
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    expressionPrefix As String _
)
Dim expressionPrefix As String

Dim instance As New ExpressionPrefixAttribute(expressionPrefix)
public ExpressionPrefixAttribute (
    string expressionPrefix
)
public:
ExpressionPrefixAttribute (
    String^ expressionPrefix
)
public ExpressionPrefixAttribute (
    String expressionPrefix
)
public function ExpressionPrefixAttribute (
    expressionPrefix : String
)

パラメータ

expressionPrefix

現在の ExpressionBuilder のプレフィックス。

解説解説

プレフィックス識別子を使用して ExpressionPrefixAttribute クラスのインスタンスを初期化するには、ExpressionPrefixAttribute コンストラクタを使用します。ExpressionPrefixAttribute は、ExpressionPrefixAttribute クラスの既定のコンストラクタです。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ExpressionPrefixAttribute クラス
ExpressionPrefixAttribute メンバ
System.Web.Compilation 名前空間

ExpressionPrefixAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ ExpressionPrefix 現在の ExpressionBuilder オブジェクトのプレフィックス値を取得します。
パブリック プロパティ TypeId  派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。 ( Attribute から継承されます。)
参照参照

関連項目

ExpressionPrefixAttribute クラス
System.Web.Compilation 名前空間
ExpressionEditor
ExpressionEditorSheet
AppSettingsExpressionEditor
ExpressionBuilder クラス
ExpressionPrefix

ExpressionPrefixAttribute メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ExpressionPrefixAttribute クラス
System.Web.Compilation 名前空間
ExpressionEditor
ExpressionEditorSheet
AppSettingsExpressionEditor
ExpressionBuilder クラス
ExpressionPrefix

ExpressionPrefixAttribute メンバ

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

ExpressionPrefixAttribute データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド ExpressionPrefixAttribute ExpressionPrefixAttribute クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ ExpressionPrefix 現在の ExpressionBuilder オブジェクトのプレフィックス値を取得します。
パブリック プロパティ TypeId  派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。(Attribute から継承されます。)
パブリック メソッドパブリック メソッド
( プロテクト メソッド も参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスの Type を取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String を返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ExpressionPrefixAttribute クラス
System.Web.Compilation 名前空間
ExpressionEditor
ExpressionEditorSheet
AppSettingsExpressionEditor
ExpressionBuilder クラス
ExpressionPrefix



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「ExpressionPrefixAttribute」の関連用語

ExpressionPrefixAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ExpressionPrefixAttributeのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS