Click here to Skip to main content
15,888,037 members
Home / Discussions / C#
   

C#

 
Questionsql to C#.net databinding Pin
User 1138061130-Jan-15 3:52
User 1138061130-Jan-15 3:52 
AnswerRe: sql to C#.net databinding Pin
OriginalGriff30-Jan-15 4:00
mveOriginalGriff30-Jan-15 4:00 
GeneralRe: sql to C#.net databinding Pin
User 1138061130-Jan-15 4:13
User 1138061130-Jan-15 4:13 
AnswerRe: sql to C#.net databinding Pin
Simon_Whale30-Jan-15 4:13
Simon_Whale30-Jan-15 4:13 
GeneralRe: sql to C#.net databinding Pin
User 1138061130-Jan-15 4:27
User 1138061130-Jan-15 4:27 
QuestionSWF File version 9 decompiling in c# Pin
krvasanth30-Jan-15 1:26
krvasanth30-Jan-15 1:26 
AnswerRe: SWF File version 9 decompiling in c# Pin
Eddy Vluggen30-Jan-15 5:14
professionalEddy Vluggen30-Jan-15 5:14 
Question(solved) WinForms: run-time loading of UserControl .dll that implements an Interface ? Pin
BillWoodruff29-Jan-15 21:17
professionalBillWoodruff29-Jan-15 21:17 
Edit: Thanks to Eddy Vluggen, and Freak30, problem resolved. The solution was that I needed to create a separate .dll containing only the Interface, and then have both the host application, and the dynamically loaded UserControl, reference the Interface .dll.
I define a Control Library in WinForms: it implements two Types: a UserControl, and an Interface, Iinterface. The UserControl, of course, implements the Interface.

Using the standard methods:
1. Assembly LoadedAssembly = Assembly.LoadFile(... filePath to usercontrol .dll ...);

2a. Type LoadedIInterfaceType = LoadedAssembly.GetTypes()[0]; // get the Type of the Interface
2b. Type LoadedUCType = LoadedAssembly.GetTypes()[1]; // get the Type of the UserControl

3. UserControl loadedUC = (UserControl)Activator.CreateInstance(LoadedUCType);
This does load, and instantiate, the UserControl at run-time. Of course, because I've cast the loaded UserControl to the "vanilla" UserControl base-Type, any public Fields/Properties/Methods I've deliberately exposed in the UserControl definition are not available.

If I have the loading Application define the same Interface:
C#
// example
interface Iinterface
{
   // some public property in the UserControl
   // which is implemented in the UserControl
   string ID { set; get; }
}
Casting the UserControl instnace that shared that interface ... or any interface ... in the loading App would be pointless since that would just produce 'null.

Is there any way I can use the loaded interface Type from step 2a. above to cast the loaded UserControl to the Interface and thus expose its public Fields/Properties/Methods, etc. ?

I am aware I can use reflection to access the internal Fields/Methods that are prescribed by the interface, but I'd much rather ... if it's possible ... get everything in the UserControl that is prescribed in the Interface ... out there.

I can confirm I have a valid reference to the interface in step 2.a above by inserting this code and setting a break-point; all the expected elements are exposed:
C#
var methods = LoadedIInterfaceType .GetMethods();
var types = LoadedIInterfaceType .GetProperties();
var fields = LoadedIInterfaceType .GetFields();
To use that old cliche: "what am I missing, here?"

thanks, Bill
«I'm asked why doesn't C# implement feature X all the time. The answer's always the same: because no one ever designed, specified, implemented, tested, documented, shipped that feature. All six of those things are necessary to make a feature happen. They all cost huge amounts of time, effort and money.» Eric Lippert, Microsoft, 2009


modified 30-Jan-15 11:02am.

AnswerRe: WinForms: run-time loading of UserControl .dll that implements an Interface ? Pin
Eddy Vluggen30-Jan-15 0:29
professionalEddy Vluggen30-Jan-15 0:29 
GeneralRe: WinForms: run-time loading of UserControl .dll that implements an Interface ? Pin
BillWoodruff30-Jan-15 4:32
professionalBillWoodruff30-Jan-15 4:32 
GeneralRe: WinForms: run-time loading of UserControl .dll that implements an Interface ? Pin
Eddy Vluggen30-Jan-15 5:11
professionalEddy Vluggen30-Jan-15 5:11 
GeneralRe: WinForms: run-time loading of UserControl .dll that implements an Interface ? Pin
BillWoodruff30-Jan-15 6:45
professionalBillWoodruff30-Jan-15 6:45 
GeneralRe: WinForms: run-time loading of UserControl .dll that implements an Interface ? Pin
Eddy Vluggen30-Jan-15 7:15
professionalEddy Vluggen30-Jan-15 7:15 
AnswerRe: WinForms: run-time loading of UserControl .dll that implements an Interface ? Pin
Freak3030-Jan-15 3:22
Freak3030-Jan-15 3:22 
GeneralRe: WinForms: run-time loading of UserControl .dll that implements an Interface ? Pin
BillWoodruff30-Jan-15 4:33
professionalBillWoodruff30-Jan-15 4:33 
Questiongetting os info of local network Pin
JSingh_Freelancer29-Jan-15 20:47
JSingh_Freelancer29-Jan-15 20:47 
QuestionRe: getting os info of local network Pin
Richard MacCutchan29-Jan-15 22:59
mveRichard MacCutchan29-Jan-15 22:59 
AnswerRe: getting os info of local network Pin
OriginalGriff30-Jan-15 0:08
mveOriginalGriff30-Jan-15 0:08 
GeneralRe: getting os info of local network Pin
JSingh_Freelancer30-Jan-15 0:16
JSingh_Freelancer30-Jan-15 0:16 
GeneralRe: getting os info of local network Pin
OriginalGriff30-Jan-15 0:23
mveOriginalGriff30-Jan-15 0:23 
AnswerRe: getting os info of local network Pin
Pete O'Hanlon30-Jan-15 1:15
mvePete O'Hanlon30-Jan-15 1:15 
QuestionWhy should I use Interface type of object in Constructor instead of Actual Class Object Pin
Amy Dev29-Jan-15 0:26
Amy Dev29-Jan-15 0:26 
AnswerRe: Why should I use Interface type of object in Constructor instead of Actual Class Object Pin
kakan29-Jan-15 0:31
professionalkakan29-Jan-15 0:31 
GeneralRe: Why should I use Interface type of object in Constructor instead of Actual Class Object Pin
Amy Dev29-Jan-15 1:04
Amy Dev29-Jan-15 1:04 
AnswerRe: Why should I use Interface type of object in Constructor instead of Actual Class Object Pin
Agent__00729-Jan-15 0:34
professionalAgent__00729-Jan-15 0:34 

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.