Using the include filterNReflect

This sample shows how to use the include filter.

Using the include filter

Suppose we want to reflect all public elements of an assembly. To achieve that, we will use the include filter. It gets a set of rules to determine what to reflect. The following code shows how to get the desired behavior:

Example

 1// Create the filter 
 2IncludeFilter includeFilter = new IncludeFilter();
 3includeFilter.Rules.Add(new FilterRule(FilterModifiers.Public, FilterElements.AllElements));
 4 
 5// Do the reflection 
 6NRAssembly nrAssembly;
 7IFilter filter = includeFilter;
 8try 
 9{
10  Reflector reflector = new Reflector();
11  nrAssembly = reflector.Reflect("MyAssembly.dll", ref filter);
12}
13catch(Exception ex)
14{
15  Console.WriteLine("Exception while reflecting: " + ex.Message);
16  return;
17}
18 
19// Output the results 
20PrintVisitor printVisitor = new PrintVisitor();
21nrAssembly.Accept(printVisitor);
See Also

Reference

Other Resources