Type::FilterAttribute Field


Represents the member filter used on attributes. This field is read-only.

Namespace:   System
Assembly:  mscorlib (in mscorlib.dll)

static initonly MemberFilter^ FilterAttribute

This field holds a reference to the delegate used by the FindMembers method. The method encapsulated by this delegate takes two parameters: the first is a MemberInfo object and the second is an Object. The method determines whether the MemberInfo object matches the criteria specified by the Object. The Object may be assigned the value of any one of the fields on the classes FieldAttributes, MethodAttributes, or MethodImplAttributes.

For example, the Object can be assigned the value of a field from FieldAttributes such as Public. In that case, when the FilterAttribute delegate is invoked, it will return true only if the method represented by the MemberInfo object is decorated with the public field attribute in metadata.

The following example gets the FilterAttribute delegate, passes it as a parameter to the FindMembers method, and displays the specified members and their attributes.

using namespace System;
using namespace System::Collections;
using namespace System::Reflection;
using namespace System::Security;
int main()
      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 );


.NET Framework
Available since 1.1
Return to top