TemplateInstanceAttribute.IsDefaultAttribute 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回一个值,该值指示当前 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 字段。