TemplateInstanceAttribute.IsDefaultAttribute Méthode

Définition

Retourne une valeur indiquant si l’objet TemplateInstanceAttribute actuel est identique à l’objet TemplateInstanceAttribute par défaut.

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

Retours

true si la valeur de l'instance actuelle de TemplateInstanceAttribute est la valeur, par défaut, sinon false.

Exemples

L'exemple de code suivant illustre l'utilisation de la méthode IsDefaultAttribute. Dans le Page_Load cas d’une page ASPX, la MyLoginViewA classe du TemplateInstanceAttribute contrôle personnalisé pour la AnonymousTemplate propriété est interrogée.

Pour obtenir la définition du MyLoginViewA contrôle, consultez 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

Remarques

La valeur par défaut de la TemplateInstanceAttribute classe est le Multiple champ .

S’applique à

Voir aussi