ploeh/Albedo — pull request #5 by adamchester (2013-10-08 16:17:10+00:00)
Title: Added visitor code

This pull request creates the Visitor API described in AutoFixture/AutoFixture#184 and AutoFixture/AutoFixture#167.

This visitor API was proposed by @ploeh in response to issues encountered throughout the AutoFixture codebase.

@ploeh said:
In the BCL, the various Reflection types aren't polymorphic. Some do share common ancestors, like MemberInfo or MethodBase, but even these base classes are of limited usefulness, because much of the interesting information is only part of the concrete classes (e.g. PropertyInfo.PropertyType versus FieldInfo.FieldType). To make matters worse, another important Reflection type, namely ParameterInfo isn't at all part of any polymorphic hierarchy.

This leads to lots of code all over the AutoFixture code base which looks like this:

```csharp
var paramInfo = obj as ParameterInfo;
if (paramInfo != null)
// do something with paramInfo

var propInfo = obj as PropertyInfo
if (propInfo != null)
// do something with propInfo

var fieldInfo = obj as FieldInfo
if (fieldInfo != null)
// do something with fieldInfo

// etc.
```

This could be addressed by defining (in the AutoFixture kernel) a Visitor for the most common Reflection types used in AutoFixture: PropertyInfo, FieldInfo, ParameterInfo, ConstructorInfo, MethodInfo...