Export (0) Print
Expand All

Type.FilterAttribute Field

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

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

'Declaration
Public Shared ReadOnly FilterAttribute As MemberFilter
'Usage
Dim value As MemberFilter

value = Type.FilterAttribute

public static final MemberFilter FilterAttribute
public static final 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.

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

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

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft