TemplateInstanceAttribute.IsDefaultAttribute Method
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a value indicating if the current TemplateInstanceAttribute object is the same as the default TemplateInstanceAttribute object.
public:
override bool IsDefaultAttribute();
public override bool IsDefaultAttribute ();
override this.IsDefaultAttribute : unit -> bool
Public Overrides Function IsDefaultAttribute () As Boolean
true
if the value of the current instance of TemplateInstanceAttribute is the default; otherwise, false
.
The following code example demonstrates how to use the IsDefaultAttribute method. In the Page_Load
event of an ASPX page, the MyLoginViewA
custom control's TemplateInstanceAttribute class for the AnonymousTemplate
property is queried.
For the definition of the MyLoginViewA
control, see 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
The default value for the TemplateInstanceAttribute class is the Multiple field.
Product | Versions |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET feedback
.NET is an open source project. Select a link to provide feedback: