How is the constructor for assembly level attribute?
Example:
[AttributeUsage(AttributeTargets.Assembly, Inherited = false, AllowMultiple = true)]
sealed class RegisterToFactoryAttribute : Attribute
{
public Type TypeToRegister { get; set; }
public RegisterToFactoryAttribute(Type typeToRegister)
{
TypeToRegister = typeToRegister;
}
}
Using:
[assembly:RegisterToFactory(typeof(MyClass))]
- CHANGE Build Level Attributes -
, , :
:
object[] attributes =
Assembly.GetExecutingAssembly().GetCustomAttributes(
typeof(RegisterToFactoryAttribute), false);
object[] attributes =
Assembly.GetExecutingAssembly().GetCustomAttributes(false);
, , @, .
- EDIT -
:
MEF?? .
:
class MyFactory
{
[ImportMany("MyFactoryExport")]
public List<Object> Registrations { get; set; }
public MyFactory()
{
AssemblyCatalog catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly());
CompositionContainer container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
}
[Export("MyFactoryExport")]
class MyClass1
{ }
[Export("MyFactoryExport")]
class MyClass2
{ }
[Export("MyFactoryExport")]
class MyClass3
{ }