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

TemplateInstanceAttribute クラス

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

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

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

<AttributeUsageAttribute(AttributeTargets.Property)> _
Public NotInheritable Class
 TemplateInstanceAttribute
    Inherits Attribute
Dim instance As TemplateInstanceAttribute
[AttributeUsageAttribute(AttributeTargets.Property)] 
public sealed class TemplateInstanceAttribute
 : Attribute
[AttributeUsageAttribute(AttributeTargets::Property)] 
public ref class TemplateInstanceAttribute
 sealed : public Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Property) */ 
public final class TemplateInstanceAttribute
 extends Attribute
AttributeUsageAttribute(AttributeTargets.Property) 
public final class TemplateInstanceAttribute
 extends Attribute
解説解説
使用例使用例

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>
.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
   System.Attribute
    System.Web.UI.TemplateInstanceAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

TemplateInstanceAttribute コンストラクタ

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

TemplateInstance 列挙値を指定して、TemplateInstanceAttribute クラスの新しいインスタンスを初期化します。

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

Public Sub New ( _
    instances As TemplateInstance _
)
Dim instances As TemplateInstance

Dim instance As New TemplateInstanceAttribute(instances)
public TemplateInstanceAttribute (
    TemplateInstance instances
)
public:
TemplateInstanceAttribute (
    TemplateInstance instances
)
public TemplateInstanceAttribute (
    TemplateInstance instances
)
public function TemplateInstanceAttribute (
    instances : TemplateInstance
)

パラメータ

instances

TemplateInstance 列挙値。

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

TemplateInstanceAttribute フィールド


パブリック フィールドパブリック フィールド

参照参照

関連項目

TemplateInstanceAttribute クラス
System.Web.UI 名前空間
TemplateInstance 列挙体

その他の技術情報

属性を使用したメタデータの拡張

TemplateInstanceAttribute プロパティ


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

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

関連項目

TemplateInstanceAttribute クラス
System.Web.UI 名前空間
TemplateInstance 列挙体

その他の技術情報

属性を使用したメタデータの拡張

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 から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

TemplateInstanceAttribute クラス
System.Web.UI 名前空間
TemplateInstance 列挙体

その他の技術情報

属性を使用したメタデータの拡張

TemplateInstanceAttribute メンバ

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

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド TemplateInstanceAttribute TemplateInstance 列挙値を指定して、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 から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

TemplateInstanceAttribute クラス
System.Web.UI 名前空間
TemplateInstance 列挙体

その他の技術情報

属性を使用したメタデータの拡張



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「TemplateInstanceAttribute」の関連用語

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

   

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



TemplateInstanceAttributeのページの著作権

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

©2026 GRAS Group, Inc.RSS