Interesting Item of the Day

In the process of making my media player, which is always changing, I wanted to add a plugin system to my player. One of the problems i always face is adding new features. Its not that i cant add them but i forget about them  and they never get done. So to alleviate that i implemented a plugin system.

It loads the dlls dynamically and i needed to figure out how to see if a class implemented the interface for the plugin, so that i could load only the ones who implment the interface in and i came across this jewel.

Type.IsAssignableFrom(type) is the piece of code that allowed for this to work correctly. heres snippet.

            Dim assm As Assembly = Assembly.LoadFrom(dlllocation)

            For Each assmtype As Type In assm.GetTypes

                If GetType(PluginContainer.IPlugin).IsAssignableFrom(assmtype) AndAlso Not assmtype.IsAbstract Then
                End If


With this i was able load the dll, get all the classes and the see if any of them implement the interface. if they do then you can just show those and then for me i load them up to be used in the media player later. You can do anything you want with it.

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

3 Responses to Interesting Item of the Day

Leave a Reply

Your email address will not be published.