Click here to Skip to main content
15,909,193 members
Home / Discussions / C#
   

C#

 
GeneralRe: Async jScript and mshtml Pin
sterenzi27-Oct-06 5:40
sterenzi27-Oct-06 5:40 
GeneralRe: Async jScript and mshtml Pin
sterenzi27-Oct-06 5:46
sterenzi27-Oct-06 5:46 
GeneralRe: Async jScript and mshtml Pin
led mike27-Oct-06 6:57
led mike27-Oct-06 6:57 
QuestionWin application, web services, arrays of objects... Pin
Sandrina27-Oct-06 4:23
Sandrina27-Oct-06 4:23 
AnswerRe: Win application, web services, arrays of objects... Pin
Dustin Metzgar27-Oct-06 8:36
Dustin Metzgar27-Oct-06 8:36 
GeneralRe: Win application, web services, arrays of objects... Pin
Sandrina29-Oct-06 23:04
Sandrina29-Oct-06 23:04 
QuestionNeed Serious Help!!! Pin
Niiiissssshhhhhuuuuu27-Oct-06 4:20
Niiiissssshhhhhuuuuu27-Oct-06 4:20 
QuestionInvoke Constructor method of any class that extends an Interface without having to specifically cast each class Pin
Jost Pedro27-Oct-06 4:14
Jost Pedro27-Oct-06 4:14 
Hi guys,


I have a class that extends an IMenuProvider interface and belongs to a plug-in project. In the UI project(other project) I've developed a menuService class that finds plug-ins that implement a IMenuProvider interface and execute the constructor method by using the invoke method. Here's the code.

<code>...

 Type[] types = assembly.GetTypes();
            foreach (Type type in types)
            {
                if (type.GetInterface("IMenuProvider") != null)
                {
                    if (!ht.ContainsKey(type.FullName))
                    {
                        //get construct info.
                        ConstructorInfo cinfo = type.GetConstructor(System.Type.EmptyTypes);
                        
                        //invoke constructor 
                        IMenuProvider imp = (IMenuProvider)cinfo.Invoke(null);  **
                        ht.Add(type.FullName, imp);
                        RegisterProvider(imp);
                    }
                }
            } 
...
</code>


So what happens is the line marked with ** returns an error saying "Unable to cast object of type 'TestPlugin.PluginMenuProvider' to type 'Enki.UI.ComponentModel.IMenuProvider'."

I know that I’m attempting to invoke the constructor method of the subclass PluginMenuProvider through the extension IMenuProvider but i don’t want to have to specify every subclass that extends the IMenuProvider interface.
Now, my question is how can i invoke the constructor without having to declare and than cast each class type that extends the interface IMenuProvider like the line marked with ** does?
Best regards.


Pedro M.
AnswerRe: Invoke Constructor method of any class that extends an Interface without having to specifically cast each class Pin
led mike27-Oct-06 5:25
led mike27-Oct-06 5:25 
AnswerRe: Invoke Constructor method of any class that extends an Interface without having to specifically cast each class Pin
MGoettmann27-Oct-06 6:18
MGoettmann27-Oct-06 6:18 
AnswerRe: Invoke Constructor method of any class that extends an Interface without having to specifically cast each class Pin
S. Senthil Kumar28-Oct-06 4:11
S. Senthil Kumar28-Oct-06 4:11 
Questiongetting current logged-in user name of windows Pin
saqib8227-Oct-06 3:36
saqib8227-Oct-06 3:36 
AnswerRe: getting current logged-in user name of windows Pin
Eric Dahlvang27-Oct-06 4:00
Eric Dahlvang27-Oct-06 4:00 
QuestionIs the virtual keyword really necessary? Pin
Shy Agam27-Oct-06 3:07
Shy Agam27-Oct-06 3:07 
AnswerRe: Is the virtual keyword really necessary? Pin
Rob Philpott27-Oct-06 4:14
Rob Philpott27-Oct-06 4:14 
GeneralRe: Is the virtual keyword really necessary? Pin
Shy Agam27-Oct-06 4:19
Shy Agam27-Oct-06 4:19 
GeneralRe: Is the virtual keyword really necessary? Pin
Rob Philpott27-Oct-06 4:31
Rob Philpott27-Oct-06 4:31 
AnswerRe: Is the virtual keyword really necessary? Pin
Guffa27-Oct-06 4:34
Guffa27-Oct-06 4:34 
GeneralRe: Is the virtual keyword really necessary? Pin
Shy Agam27-Oct-06 4:36
Shy Agam27-Oct-06 4:36 
QuestionParameterized transactions & non-parameterised transacions Pin
Haseeb Mukhtar27-Oct-06 2:58
Haseeb Mukhtar27-Oct-06 2:58 
AnswerRe: Parameterized transactions & non-parameterised transacions Pin
Dustin Metzgar27-Oct-06 8:38
Dustin Metzgar27-Oct-06 8:38 
GeneralABT C# Pin
sanki77927-Oct-06 2:18
sanki77927-Oct-06 2:18 
GeneralRe: ABT C# Pin
ednrgc27-Oct-06 2:20
ednrgc27-Oct-06 2:20 
GeneralRe: ABT C# Pin
sanki77927-Oct-06 2:47
sanki77927-Oct-06 2:47 
GeneralRe: ABT C# Pin
ednrgc27-Oct-06 2:59
ednrgc27-Oct-06 2:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.