TemplateInstanceAttribute.IsDefaultAttribute 메서드

정의

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

public:
 override bool IsDefaultAttribute();
public override bool IsDefaultAttribute();
override this.IsDefaultAttribute : unit -> bool
Public Overrides Function IsDefaultAttribute () As Boolean

반품

true 현재 인스턴스 TemplateInstanceAttribute 의 값이 기본값이면 .이고, false그렇지 않으면 .

예제

다음 코드 예제에서는 메서드를 사용 하는 방법을 보여 줍니다 IsDefaultAttribute . Page_Load ASPX 페이지의 경우 속성에 MyLoginViewA 대한 사용자 지정 컨트롤의 TemplateInstanceAttribute 클래스가 AnonymousTemplate 쿼리됩니다.

컨트롤의 정의는 MyLoginViewA .를 참조하세요 TemplateInstanceAttribute.

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.");
  }

}
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

설명

클래스의 TemplateInstanceAttribute 기본값은 필드입니다 Multiple .

적용 대상

추가 정보