Type.FilterAttribute 字段
表示用在属性 (Attribute) 上的成员筛选器。此字段为只读。
**命名空间:**System
**程序集:**mscorlib(在 mscorlib.dll 中)
语法
声明
Public Shared ReadOnly FilterAttribute As MemberFilter
用法
Dim value As MemberFilter
value = Type.FilterAttribute
public static readonly MemberFilter FilterAttribute
public:
static initonly MemberFilter^ FilterAttribute
public static final MemberFilter FilterAttribute
public static final var FilterAttribute : MemberFilter
备注
此字段含有对 FindMembers 方法使用的委托的引用。此委托封装的方法使用两个参数:第一个是 MemberInfo 对象,第二个是 Object。此方法确定 MemberInfo 对象是否与 Object 指定的判据相匹配。Object 可能会被赋予类 FieldAttributes、MethodAttributes 或 MethodImplAttributes 上任一个字段的值。
例如,Object 可分配得到来自 FieldAttributes(如 Public)的一个字段的值。在这种情况下,当调用 FilterAttribute 委托时,只有在 MemberInfo 对象表示的方法用元数据中的公共字段属性修饰时,它才返回 true。
示例
下面的示例获取 FilterAttribute 委托,将其作为参数传递给 FindMembers 方法,然后显示指定的成员和它们的属性。
Imports System
Imports System.Reflection
Imports System.Security
Imports Microsoft.VisualBasic
Public Class MyFilterAttributeSample
Public Shared Sub Main()
Try
Dim myFilter As MemberFilter = Type.FilterAttribute
Dim myType As Type = GetType(System.String)
Dim myMemberInfoArray As MemberInfo() = myType.FindMembers(MemberTypes.Constructor Or MemberTypes.Method, BindingFlags.Public Or BindingFlags.Static Or BindingFlags.Instance, myFilter, MethodAttributes.SpecialName)
Dim myMemberinfo As MemberInfo
For Each myMemberinfo In myMemberInfoArray
Console.Write(ControlChars.newline + myMemberinfo.Name)
Console.Write(" is a " + myMemberinfo.MemberType.ToString())
Next myMemberinfo
Catch e As ArgumentNullException
Console.Write("ArgumentNullException : " + e.Message.ToString())
Catch e As SecurityException
Console.Write("SecurityException : " + e.Message.ToString())
Catch e As Exception
Console.Write("Exception :" + e.Message.ToString())
End Try
End Sub 'Main
End Class 'MyFilterAttributeSample
using System;
using System.Reflection;
using System.Security;
public class MyFilterAttributeSample
{
public static void Main()
{
try
{
MemberFilter myFilter = Type.FilterAttribute;
Type myType = typeof(System.String);
MemberInfo[] myMemberInfoArray = myType.FindMembers(MemberTypes.Constructor
|MemberTypes.Method, BindingFlags.Public | BindingFlags.Static |
BindingFlags.Instance, myFilter, MethodAttributes.SpecialName);
foreach (MemberInfo myMemberinfo in myMemberInfoArray)
{
Console.Write ("\n" + myMemberinfo.Name);
Console.Write (" is a " + myMemberinfo.MemberType.ToString());
}
}
catch(ArgumentNullException e)
{
Console.Write("ArgumentNullException : " + e.Message);
}
catch(SecurityException e)
{
Console.Write("SecurityException : " + e.Message);
}
catch(Exception e)
{
Console.Write("Exception :" + e.Message);
}
}
}
using namespace System;
using namespace System::Collections;
using namespace System::Reflection;
using namespace System::Security;
int main()
{
try
{
MemberFilter^ myFilter = Type::FilterAttribute;
Type^ myType = System::String::typeid;
array<MemberInfo^>^myMemberInfoArray = myType->FindMembers( static_cast<MemberTypes>(MemberTypes::Constructor | MemberTypes::Method), static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static | BindingFlags::Instance), myFilter, MethodAttributes::SpecialName );
IEnumerator^ myEnum = myMemberInfoArray->GetEnumerator();
while ( myEnum->MoveNext() )
{
MemberInfo^ myMemberinfo = safe_cast<MemberInfo^>(myEnum->Current);
Console::Write( "\n {0}", myMemberinfo->Name );
Console::Write( " is a {0}", myMemberinfo->MemberType );
}
}
catch ( ArgumentNullException^ e )
{
Console::Write( "ArgumentNullException : {0}", e->Message );
}
catch ( SecurityException^ e )
{
Console::Write( "SecurityException : {0}", e->Message );
}
catch ( Exception^ e )
{
Console::Write( "Exception : {0}", e->Message );
}
}
import System.*;
import System.Reflection.*;
import System.Security.*;
public class MyFilterAttributeSample
{
public static void main(String[] args)
{
try {
MemberFilter myFilter = Type.FilterAttribute;
Type myType = System.String.class.ToType();
MemberInfo myMemberInfoArray[] =
myType.FindMembers(MemberTypes.Constructor | MemberTypes.Method,
BindingFlags.Public | BindingFlags.Static
| BindingFlags.Instance, myFilter, MethodAttributes.SpecialName);
for (int iCtr = 0; iCtr < myMemberInfoArray.length; iCtr++) {
MemberInfo myMemberinfo = myMemberInfoArray[iCtr];
Console.Write("\n" + myMemberinfo.get_Name());
Console.Write(" is a "
+ myMemberinfo.get_MemberType().ToString());
}
}
catch (ArgumentNullException e) {
Console.Write("ArgumentNullException : " + e.get_Message());
}
catch (SecurityException e) {
Console.Write("SecurityException : " + e.get_Message());
}
catch (System.Exception e) {
Console.Write("Exception :" + e.get_Message());
}
} //main
} //MyFilterAttributeSample
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0