This documentation is archived and is not being maintained.

Type.FilterAttribute Field

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

[Visual Basic]
Public Shared ReadOnly FilterAttribute As MemberFilter
public static readonly MemberFilter FilterAttribute;
public: static MemberFilter* FilterAttribute;
public static var FilterAttribute : MemberFilter;


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.


[Visual Basic, C#, C++] The following example gets the FilterAttribute delegate, passes it as a parameter to the FindMembers method, and displays the specified members and their attributes.

[Visual Basic] 
Imports System
Imports System.Reflection
Imports System.Security
Imports Microsoft.VisualBasic

Public Class MyFilterAttributeSample

    Public Shared Sub Main()
            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()
            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 <mscorlib.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Reflection;
using namespace System::Security;

int main() {
   try {
      MemberFilter*  myFilter = Type::FilterAttribute;
      Type*  myType = __typeof(System::String);
      MemberInfo*  myMemberInfoArray[] = myType->FindMembers(
         static_cast<MemberTypes>(MemberTypes::Constructor |MemberTypes::Method),
         static_cast<BindingFlags>(BindingFlags::Public | BindingFlags::Static | BindingFlags::Instance),
         myFilter, __box(MethodAttributes::SpecialName));
      IEnumerator* myEnum = myMemberInfoArray->GetEnumerator();
      while (myEnum->MoveNext()) {
         MemberInfo* myMemberinfo = __try_cast<MemberInfo*>(myEnum->Current);

         Console::Write (S"\n {0}", myMemberinfo->Name);
         Console::Write (S" is a {0}", __box(myMemberinfo->MemberType)); 
   } catch (ArgumentNullException* e) {
      Console::Write(S"ArgumentNullException : {0}", e->Message); 
   } catch (SecurityException* e) {
      Console::Write(S"SecurityException : {0}", e->Message); 
   } catch (Exception* e) {
      Console::Write(S"Exception : {0}", e->Message); 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Type Class | Type Members | System Namespace | FindMembers | MemberFilter