ExpressionPrefixAttribute クラス
アセンブリ: System.Web (system.web.dll 内)

<AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple:=False)> _ Public NotInheritable Class ExpressionPrefixAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple=false)] public sealed class ExpressionPrefixAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class, AllowMultiple=false)] public ref class ExpressionPrefixAttribute sealed : public 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.Attribute
System.Web.Compilation.ExpressionPrefixAttribute


Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からExpressionPrefixAttribute クラスを検索する場合は、下記のリンクをクリックしてください。

- ExpressionPrefixAttribute クラスのページへのリンク