Importing/Exporting From Hard Disk?

Oct 4, 2010 at 3:15 AM
Edited Oct 4, 2010 at 3:16 AM

I have an idea where a user can drag a file onto my application and it will create an extension for it to use later on. For this to work though i would need some way to Create the extension at runtime, store it somewhere, and then load it with MEF when the application starts.

So is it possible for mef to import from say an xml file? or does it have to be imported from an assembly? 

Oct 8, 2010 at 11:01 PM

any suggestions on how to do this?

Oct 9, 2010 at 12:11 AM

That would be fairly easy to do. First, you would have to determine if the file dropped is actually an addin, with a .dll extension. Then it would have to be copied to a specific folder (e.g. c:\Program Files\Your Application\) and then restart the app. Good idea!

Oct 9, 2010 at 12:30 AM

ahh, sorry maybe i didn't explain my idea well enough. the file dropped is just a file. not a dll, what i want to do is construct an extension based on a pre defined contract that contains details about that file. Like name, location, icon. Because its not a dll and will be constructed at run time i'm not sure if there is a way that i can store the details so MEF can load it? i'm thinking it would best to serialise and store the object in an xml file. but then what? Can i de-serialize the object and import it into MEF even though it will only exist in memory at this point. My understanding of mef is that it handles the instantiation of objects so is it possible to import an object already instantiated?

Oct 9, 2010 at 4:31 AM
Yes. The Container has a SatisfyImportsOnce method that you can use to 'dip' an existing instance that has property imports, or which has exports.

If you are emitting types on the fly, you can also use TypeCatalog / AssemblyCatalog to load them.

On Oct 8, 2010, at 5:31 PM, "nitro52" <notifications@codeplex.com> wrote:

From: nitro52

ahh, sorry maybe i didn't explain my idea well enough. the file dropped is just a file. not a dll, what i want to do is construct an extension based on a pre defined contract that contains details about that file. Like name, location, icon. Because its not a dll and will be constructed at run time i'm not sure if there is a way that i can store the details so MEF can load it? i'm thinking it would best to serialise and store the object in an xml file. but then what? Can i de-serialize the object and import it into MEF even though it will only exist in memory at this point. My understanding of mef is that it handles the instantiation of objects so is it possible to import an object already instantiated?

Oct 9, 2010 at 4:52 AM

ah ok, i'll try that out and see how i go

thanks