Geeks With Blogs


Microsoft Store

Support This Site

AddThis Social Bookmark Button

Locations of visitors to this page

Subscribers to this feed

TwitterCounter for @sdorman

Creative Commons License

Scott Dorman Microsoft MVP, Software Architect, Developer, Author

I am a big fan of using XML comments in code and actually have a few Visual Studio macros which allow me to “inherit” the documentation from an overridden member. Every once in a while, I end up pulling in a comment with a filterpriority XML tag. This tag is very prevalent in the BCL but I have never been able to find documentation on what it actually means.

To see what I mean, let’s take a look at part of the definition for System.Object. In the XML comments, you will see that the class itself has a <filterpriority>1</filterpriority> and that the Equals method has a <filterpriority>2</filterpriority>.

   1: namespace System   
   2:  {
   3:      /// <summary>Supports all classes in the .NET Framework class hierarchy 
   4:      /// and provides low-level services to derived classes. This is the 
   5:      /// ultimate base class of all classes in the .NET Framework; it is the
   6:      /// root of the type hierarchy.</summary>
   7:      /// <filterpriority>1</filterpriority> 
   8:      [System.Runtime.InteropServices.ClassInterfaceAttribute(2)]
   9:      public class Object    
  10:      {    
  11:          /// <summary>Determines whether the specified 
  12:          /// <see cref="T:System.Object" /> 
  13:          /// instances are considered equal.</summary>  
  14:          /// <returns>true if objA is the same instance as objB or
  15:          /// if both are null
  16:          /// references or if objA.Equals(objB) returns true; 
  17:          /// otherwise, false.</returns>
  18:          /// <param name="objB">The second <see cref="T:System.Object" /> 
  19:          /// to compare. </param>
  20:          /// <param name="objA">The first <see cref="T:System.Object" /> 
  21:          /// to compare. </param>
  22:          /// <filterpriority>2</filterpriority>
  23:          public static bool Equals(object objA, object objB);
  24:       }
  25:   }

The only real mention I was able to find was this blog post, which is actually talking about the “Go to definition” feature of Visual Studio. One of the comments asks about the <filterpriority> tag. Unfortunately, when I saw this blog post and the comments, I misread the second comment and thought that it applied to the first comment about the <filterpriority>. As it turns out, the comment was talking about the “Go to definition” feature itself.

Since I wanted to know the answer, I posted a question on StackOverflow. The first answer seemed to indicate that this applied to the “All” and “Common” tabs in the VB.NET editors intellisense implementation, but (due to having misread the blog post comments) I dismissed that thinking this was a C# feature. A second answer just a few days ago said that this was somehow tied to the EditorBrowsableAttribute (and more specifically the values of the EditorBrowsableState enum. I couldn’t see how an XML comment could be the same as decorating the member with the attribute.

As a result, I started doing some more digging and came across a self-published book titled XML Document Guide, which actually documented the <filterpriority> tag (page 30). According to that book, the value of this tag is:

Used by the Visual Basic editor in order to determine whether a member should appear on the Common or All tab when the completion list is shown.

That led me to start doing some testing of my own to verify things.

The first thing I discovered is that it appears to have no effect on classes. This is contrary to what I would have thought since Microsoft places filterpriority tags on classes. Getting past that discrepancy, it became very clear that the filterpriority tag controls the IntelliSense visibility for both methods and properties whether they are instance members or static members. Testing on Visual Studio 2008 RTM provided the following results:

Filter Priority value









missing Common Common Common Common
0 Common Common Common Common
1 Common Common Common Common
2 All All All All
3 Hidden*  Hidden Hidden Hidden

* Initial testing on VS2008 SP1 showed this method available on the All tab.

Where things start to become really interesting is when you combine the filterpriority tag with the EditorBrowsableAttribute. This attribute specifies if a method or property is viewable in an editor and allows you to specify a state of Always, Advanced, or Never. At first glance this appears to cause the same behavior as the filterpriority tag with the benefit that any language editor will respect the attribute.

But what happens if you specify both the filterpriority tag and the EditorBrowsableAttribute? When tested on VS2008 RTM, the filterpriority tag took precedence over the EditorBrowsableAttribute and the results were exactly the same as if the attribute were not present. However, when using EditorBrowsableState.Never, the attribute took precedence over the filterpriority tag and none of the methods displayed in the IntelliSense list.

I did notice that the results did not seem 100% repeatable so, for now I would be a bit cautious relying on the filterpriority tag. I’m going to see if I can get someone from either the VB or Visual Studio teams to comment and provide some definitive information on how this tag behaves, but until then the only certainty is that it does control whether a member appears on the Common or All tab for the Visual Basic IntelliSense list.

DotNetKicks Image
Posted on Thursday, January 8, 2009 8:55 PM .NET (General) | Back to top

Copyright © Scott Dorman | Powered by: | Join free