c# - MEF. Enforce PartCreationPolicy to be CreationPolicy.Shared in custom ExportAttribute -


i have following custom attribute inherits mef's exportattribute:

[attributeusage(attributetargets.class)] public class definesettingsattribute : exportattribute {      public definesettingsattribute() : base(typeof(definesettingsattribute)) { } } 

i enforce shared creation policy in classes decorated attribute. can achieve with:

[definesettings] [partcreationpolicy(creationpolicy.shared)] public class foo { } 

this way import explicit non-shared fail. nevertheless need no make custom attribute, final code looks this:

[definesettings] public class foo { } 

the way have made work discovering decorated types , add them partcreationpolicy attribute using reflection. wonder if there more elegant , better way.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -