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 列挙

その他の技術情報

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



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

辞書ショートカット

すべての辞書の索引

「TemplateInstanceAttribute」の関連用語

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

   

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



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

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

©2025 GRAS Group, Inc.RSS