The easiest way to do this is probably through a custom specimen builder:
public class OmitPropertyForTypeInNamespace : ISpecimenBuilder
{
private readonly string ns;
public OmitPropertyForTypeInNamespace(string ns)
{
this.ns = ns;
}
public object Create(object request, ISpecimenContext context)
{
if (IsProperty(request) &&
IsDeclaringTypeInNamespace((PropertyInfo)request))
{
return new OmitSpecimen();
}
return new NoSpecimen(request);
}
private bool IsProperty(object request)
{
return request is PropertyInfo;
}
private bool IsDeclaringTypeInNamespace(PropertyInfo property)
{
var declaringType = property.DeclaringType;
return declaringType.Namespace.Equals(
this.ns,
StringComparison.OrdinalIgnoreCase);
}
}
As usual, it's a good convention to also provide a matching customization:
public class OmitAutoPropertiesForTypesInNamespace : ICustomization
{
private readonly string ns;
public OmitAutoPropertiesForTypesInNamespace(string ns)
{
this.ns = ns;
}
public void Customize(IFixture fixture)
{
fixture.Customizations.Add(new OmitPropertyForTypeInNamespace(this.ns));
}
}
This will ultimately allow you to say:
var fixture = new Fixture();
fixture.Customize(new OmitAutoPropertiesForTypesInNamespace("MyProject"));