共用方式為


TemplateInstanceAttribute.IsDefaultAttribute 方法

定義

傳回一個值,以指示目前的 TemplateInstanceAttribute 物件是否和預設的 TemplateInstanceAttribute 物件相同。

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

傳回

如果 TemplateInstanceAttribute目前的執行個體值為預設值,則為 true,否則為 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 欄位。

適用於

另請參閱