TemplateInstanceAttribute 클래스

정의

허용되는 템플릿 인스턴스의 수를 지정하는 데 사용되는 메타데이터 특성을 정의합니다. 이 클래스는 상속될 수 없습니다.

public ref class TemplateInstanceAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Property)]
public sealed class TemplateInstanceAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Property)>]
type TemplateInstanceAttribute = class
    inherit Attribute
Public NotInheritable Class TemplateInstanceAttribute
Inherits Attribute
상속
TemplateInstanceAttribute
특성

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 TemplateInstance 열거 및 TemplateInstanceAttribute 클래스입니다. 사용자 지정 LoginView 라는 컨트롤 MyLoginViewA 재정의 AnonymousTemplate 사용 하 여 속성을 TemplateInstanceAttribute 클래스의 인스턴스를 하나만 지정 하는 AnonymousTemplate 속성이 만들어집니다.

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;
            }
        }
    }
}
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

다음 코드 예제를 사용 하는 ASPX 파일은는 MyLoginViewA 제어 하 고 속성에 액세스 하는 방법을 보여 줍니다는 TemplateInstanceAttribute 클래스입니다.

<%@ 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">
   
  // <Snippet3> 
  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.");
    }

  }
  // </Snippet3> 

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<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="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">

  ' <Snippet3>
  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
  ' </Snippet3>
  
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<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>

설명

TemplateInstanceAttribute 클래스를 사용 하면 단일을 허용 하는 하나 또는 여러 인스턴스 템플릿 속성을 표시할 수 있습니다. 만 단일 인스턴스화를 허용 하는 템플릿 내부 참조에 포함 된 컨트롤에 있을 수 있습니다. ZoneTemplate 속성은 한 번만 인스턴스화되는 속성의 예입니다.

TemplateInstanceAttribute 클래스는 선택 사항입니다. 템플릿 속성을 사용 하 여 확장 되지 않은 경우는 TemplateInstanceAttribute 클래스, 기본값인은 Multiple 필드에 사용 됩니다. 특성을 사용 하는 방법에 대 한 자세한 내용은 참조 하세요. 특성합니다.

생성자

TemplateInstanceAttribute(TemplateInstance)

지정된 TemplateInstanceAttribute 열거형 값을 사용하여 TemplateInstance 클래스의 새 인스턴스를 초기화합니다.

필드

Default

TemplateInstanceAttribute 클래스의 기본값을 정의합니다. 이 필드는 읽기 전용입니다.

Multiple

TemplateInstanceAttribute 클래스의 인스턴스를 여러 번 인스턴스화되는 템플릿을 나타내는 인스턴스로 만듭니다. 이 필드는 읽기 전용입니다.

Single

TemplateInstanceAttribute 클래스의 인스턴스를 한 번 인스턴스화되는 템플릿을 나타내는 인스턴스로 만듭니다. 이 필드는 읽기 전용입니다.

속성

Instances

현재 템플릿 인스턴스가 나타내는 TemplateInstance 열거형 값을 가져옵니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

지정한 개체가 TemplateInstanceAttribute 개체이고 이 TemplateInstanceAttribute 개체와 같은지 여부를 나타냅니다.

GetHashCode()

해당 TemplateInstanceAttribute 개체의 해시 코드를 가져옵니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

현재 TemplateInstanceAttribute 개체가 기본 TemplateInstanceAttribute 개체와 동일한지 여부를 나타내는 값을 반환합니다.

Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상

추가 정보