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

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > 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


このページでは「.NET Framework クラス ライブラリ リファレンス」からExpressionPrefixAttribute クラスを検索した結果を表示しています。
Weblioに収録されているすべての辞書からExpressionPrefixAttribute クラスを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からExpressionPrefixAttribute クラス を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ExpressionPrefixAttribute クラス」の関連用語

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

   

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



ExpressionPrefixAttribute クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS