Why is this an issue?
The PartCreationPolicyAttribute
attribute, which is part of the Managed Extensibility Framework (MEF), is used to specify how the
exported object will be created. Therefore it doesn’t make sense not to export this a class with this attribute using the ExportAttribute
attribute.
This rule raises an issue when a class is marked as shared with a PartCreationPolicyAttribute
but lacks a
ExportAttribute
.
Noncompliant code example
[PartCreationPolicy(CreationPolicy.Any)] // Noncompliant
public class FooBar : IFooBar
{
}
Compliant solution
[Export(typeof(IFooBar))]
[PartCreationPolicy(CreationPolicy.Any)]
public class FooBar : IFooBar
{
}