I have a class exported and in a different part of the code it is imported.
[Import]
public IEnumerable<IRTAOperatorErrorNotifications> RTAOperatorErrorNotifications
{
get { return m_RTAOperatorErrorNotifications; }
}
Now the DLL were the class resides is loaded into the application conditionally and in most cases it won't exist, so I'm wondering will this cause the program to crash if the DLL doesn't exist? What I want is for the object to simply be set to null if the DLL isn't there so I can check and do the right thing. Is there a way to conditionally import so the value is set to null if the class isn't loaded?
Thanks,
Suggested changes: since it is an IEnumerable
you need to use ImportMany
. AllowDefault = true
allows code to set it NULL
when no import was found.
[ImportMany(AllowDefault = true)]
public IEnumerable<IRTAOperatorErrorNotifications> RTAOperatorErrorNotifications { get; private set; }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.