Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Type.FilterAttribute Field

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)
public static readonly 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 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); 
        } 
    }	
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.