Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Table Driven Menus
Message
From
20/11/2009 18:34:47
 
 
To
20/11/2009 18:21:34
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01435073
Message ID:
01435885
Views:
39
OK, now I understand your confusion. I was assuming that you'd have at least some standard sets of Interfaces that you'd want to use to have communication between your app with the dynamic classes. Those interfaces would be in a totally different class/project and would need to be referenced by both your app and the dynamic classes (your SimpleClassLibrary1.Class1 types of classes).

Now, if you don't want that level of "dependency" (not the word I want, but I'm having a brain-fart and can't think of the right word at the moment), there is a way to get and call methods through Reflection. I have an example of that somewhere, but I need to dig it out ... forget where it is. Let me get back to you in a few minutes.

~~Bonnie






>>My other reply should help explain what has gone wrong here.
>>
>>First, your classname needs the full namespace, so it should be
>>
>>
>>            string classname = "SimpleClassLibrary1.Class1";
>>
>
>Ok I get that now that you mention it.
>
>>
>>I mentioned in my other reply about the use of interfaces. If you didn't use an interface that was common to a known set of dynamically instantiated objects, then you'd have to have a reference in your solution to Class1 ... which defeats the purpose of what we're trying to accomplish here.
>
>It sure would.
>
>>
>>So, say you want to have the ability to instantiate a bunch of different classes that all will implement the IShowMessage interface (which contains a method called showmessageX). So, both your SimpleClassLibrary and your other solution would both need to have that IShowMessage interface included in them.
>>
>
>This is the part I don't understand.
>
>I have added an interface to the class like this and it compiles ok. Is this part of what you mean by an Interface?
>
>
>namespace SimpleClassLibrary1
>{
>    public class Myclass : IShowMessage
>    {
>        //method
>        public bool showmessageX(string message) 
>        {
>            MessageBox.Show(message);
>            return true;
>        }
>    }
>    // interface for above method
>     interface IShowMessage
>    {
>        bool showmessageX(string message);
>    }
>}
>
>
>
>>So, both your SimpleClassLibrary and your other solution would both need to have that IShowMessage interface included in them.
>
>This is the line that throws me.
>
>How do I include something in an application when it is not even there. Let me explain what I mean.
>
>This is supposed to be a Dynamic application that can download a DLL and execute its methods using reflection. So I have a disconnected DLL where I have methods that the main app does not know about. All It knows is that it will read from a table and get the methods and classes to call from there and using Reflection instantiate those classes and call those methods.
>
>When the main App is compiled it knows nothing about SimpleClassLibrary nor its methods. It is supposed to find these out using reflection. That is the sole purpose of this exercise. So I do not understand your statement above. Including the Interface in the calling app would not be dynamic at all.
>
>Maybe I am getting this all wrong but the code segment below does not compile because the main app does not know what IShowMessage is without including it.
>
>>
>>
>>            IShowMessage o = oReflection.InstantiateClass(ref message) as IShowMessage;
>>            if (o == null)
>>                MessageBox.Show(message);
>>            else
>>            {
>>                o.showmessageX(message);
>>                
>>            }
>>
>
>From what I have seen so far, there is nothing really dynamic about this code if I have to include an interface before hand.
>
>So here I put down what I want to achieve - a really dynamic datadriven model.
>
>I have your MyReflectionClass as a separate class.
>I include it in my Main project. The Main project also has code that will read from a table, download a class and instantiate it and call a method in that class. Using Reflection. It does not need to know any of these things when it is compiled:
>
>1. The name of the DLL
>2. The name of the class
>3. The name of the method in that class to call and its parameters.
>
>All these will be read from the table at runtime, it will then download that DLL, instantiate that class, and call that method passing the parameters - all using Reflection.
>
>That is my idea of dynamic.
>
>But if I include an Interface as a bridge in both, that does not make it dynamic at all.
>
>For simplicity sake I want to restrict the Dynamic class to a single method and it is imperative that the only bridge between this class and the main app is the table which will have the full path to the DLL, the full class name including namespace and the method+parameters (if any) to call on this class as a single record.
>
>So given the above model, is it at all possible in .Net?
>
>If so could you please explain how. Maybe a blog entry and a sample to download ?
>
>Thanks
>
>Bernard
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform