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

<AttributeUsageAttribute(AttributeTargets.Property)> _ Public NotInheritable Class TemplateInstanceAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Property)] public sealed class TemplateInstanceAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Property)] public ref class TemplateInstanceAttribute sealed : public Attribute

TemplateInstanceAttribute クラスを使用して、テンプレート プロパティを、1 回または複数回のインスタンス化を許可するプロパティとしてマークできます。1 回のみのインスタンス化を許可するテンプレートでは、その中に含まれるコントロールを参照させることができます。ZoneTemplate プロパティは、1 回のみインスタンス生成できるプロパティの例です。
この TemplateInstanceAttribute クラスはオプションです。テンプレート プロパティが TemplateInstanceAttribute クラスで拡張されない場合、既定値である Multiple フィールドが使用されます。属性の使用方法については、「属性を使用したメタデータの拡張」を参照してください。

TemplateInstance 列挙体と TemplateInstanceAttribute クラスの使用方法を次のコード例に示します。MyLoginViewA という名前のカスタム LoginView コントロールが AnonymousTemplate プロパティをオーバーライドして、TemplateInstanceAttribute クラスを使用して、AnonymousTemplate プロパティを 1 回のみインスタンス生成することを指定しています。
Imports Microsoft.VisualBasic Imports System Imports System.Data Imports System.ComponentModel Imports System.Web Imports System.Web.UI Imports System.Web.UI.WebControls Namespace Samples.AspNet.VB.Controls Public Class MyLoginViewA Inherits LoginView Private _anonymoustemplate As ITemplate <Browsable(False), DefaultValue(""), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(GetType(LoginView)), TemplateInstance(TemplateInstance.Single)> _ Public Overrides Property AnonymousTemplate() As System.Web.UI.ITemplate Get Return _anonymoustemplate End Get Set(ByVal value As System.Web.UI.ITemplate) _anonymoustemplate = value End Set End Property End Class End Namespace
using System; using System.Data; using System.ComponentModel; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Samples.AspNet.CS.Controls { public class MyLoginViewA : LoginView { private ITemplate _anonymoustemplate; [Browsable(false), DefaultValue(null), PersistenceMode(PersistenceMode.InnerProperty), TemplateContainer(typeof(LoginView)), TemplateInstance(TemplateInstance.Single) ] public override ITemplate AnonymousTemplate { get { return _anonymoustemplate; } set { _anonymoustemplate = value; } } } }
MyLoginViewA コントロールを使用する ASPX ファイルと、TemplateInstanceAttribute クラスのプロパティにアクセスする方法を次のコード例に示します。
<%@ Page Language="VB" %> <%@ Import Namespace="System.Reflection" %> <%@ Register TagPrefix="AspNetSamples" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB.Controls" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) ' Get the class type for which to access metadata. Dim clsType As Type = GetType(MyLoginViewA) ' Get the PropertyInfo object for FirstTemplate. Dim pInfo As PropertyInfo = clsType.GetProperty("AnonymousTemplate") ' See if the TemplateInstanceAttribute is defined for this property. Dim isDef As Boolean = Attribute.IsDefined(pInfo, GetType(TemplateContainerAttribute)) ' Display the result if the attribute exists. If isDef Then Dim tia As TemplateInstanceAttribute = CType(Attribute.GetCustomAttribute(pInfo, GetType(TemplateInstanceAttribute)), TemplateInstanceAttribute) Response.Write("The <AnonymousTemplate> has the TemplateInstanceAttribute = " & tia.Instances.ToString() & ".<br>") If (tia.IsDefaultAttribute()) Then Response.Write("The TemplateInstanceAttribute used is the same as the default instance.") Else Response.Write("The TemplateInstanceAttribute used is not the same as the default instance.") End If End If End Sub </script> <html > <head runat="server"> <title>TemplateInstance Example</title> </head> <body> <form id="form1" runat="server"> <div> <AspNetSamples:MyLoginViewA id="MyLoginViewA1" runat="server"> <AnonymousTemplate> <asp:Label ID="LoginViewLabel1" runat="server" Text="LoginView Anonymous Template Text"/> </AnonymousTemplate> </AspNetSamples:MyLoginViewA> </div> </form> </body> </html>
<%@ Page Language="C#" %> <%@ Import Namespace="System.Reflection" %> <%@ Register TagPrefix="AspNetSamples" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS.Controls" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { // Get the class type for which to access metadata. Type clsType = typeof(MyLoginViewA); // Get the PropertyInfo object for FirstTemplate. PropertyInfo pInfo = clsType.GetProperty("AnonymousTemplate"); // See if the TemplateInstanceAttribute is defined for this property. bool isDef = Attribute.IsDefined(pInfo, typeof(TemplateInstanceAttribute)); // Display the result if the attribute exists. if (isDef) { TemplateInstanceAttribute tia = (TemplateInstanceAttribute)Attribute.GetCustomAttribute(pInfo, typeof(TemplateInstanceAttribute)); Response.Write("The <AnonymousTemplate> has the TemplateInstanceAttribute = " + tia.Instances.ToString() + ".<br>"); if (tia.IsDefaultAttribute()) Response.Write("The TemplateInstanceAttribute used is the same as the default instance."); else Response.Write("The TemplateInstanceAttribute used is not the same as the default instance."); } } </script> <html > <head runat="server"> <title>TemplateInstance Example</title> </head> <body> <form id="form1" runat="server"> <div> <AspNetSamples:MyLoginViewA id="MyLoginViewA1" runat="server"> <AnonymousTemplate> <asp:Label ID="LoginViewLabel1" runat="server" Text="LoginView Anonymous Template Text"/> </AnonymousTemplate> </AspNetSamples:MyLoginViewA> </div> </form> </body> </html>


System.Attribute
System.Web.UI.TemplateInstanceAttribute


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


TemplateInstanceAttribute コンストラクタ
アセンブリ: System.Web (system.web.dll 内)

- instances
TemplateInstance 列挙値。

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


TemplateInstanceAttribute フィールド

名前 | 説明 | |
---|---|---|
![]() | Default | TemplateInstanceAttribute クラスの既定値を定義します。このフィールドは読み取り専用です。 |
![]() | Multiple | 複数回インスタンス生成されるテンプレートを表す属性として TemplateInstanceAttribute クラスのインスタンスを作成します。このフィールドは読み取り専用です。 |
![]() | Single | 1 回だけインスタンス生成されるテンプレートを表す属性として TemplateInstanceAttribute クラスのインスタンスを作成します。このフィールドは読み取り専用です。 |

TemplateInstanceAttribute プロパティ

名前 | 説明 | |
---|---|---|
![]() | Instances | 現在のテンプレート インスタンスが表す TemplateInstance 列挙値。 |
![]() | TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。 ( Attribute から継承されます。) |

TemplateInstanceAttribute メソッド

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

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

TemplateInstanceAttribute メンバ
テンプレートの許可されるインスタンス数を指定するために使用されるメタデータ属性を定義します。このクラスは継承できません。
TemplateInstanceAttribute データ型で公開されるメンバを以下の表に示します。

名前 | 説明 | |
---|---|---|
![]() | TemplateInstanceAttribute | TemplateInstance 列挙値を指定して、TemplateInstanceAttribute クラスの新しいインスタンスを初期化します。 |

名前 | 説明 | |
---|---|---|
![]() | Default | TemplateInstanceAttribute クラスの既定値を定義します。このフィールドは読み取り専用です。 |
![]() | Multiple | 複数回インスタンス生成されるテンプレートを表す属性として TemplateInstanceAttribute クラスのインスタンスを作成します。このフィールドは読み取り専用です。 |
![]() | Single | 1 回だけインスタンス生成されるテンプレートを表す属性として TemplateInstanceAttribute クラスのインスタンスを作成します。このフィールドは読み取り専用です。 |

名前 | 説明 | |
---|---|---|
![]() | Instances | 現在のテンプレート インスタンスが表す TemplateInstance 列挙値。 |
![]() | TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。(Attribute から継承されます。) |

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

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

- TemplateInstanceAttributeのページへのリンク