There was a good thread on this as I was bumping into this myself. I ended up using reflection as there were some code generation issues for me.
An option is to do a separate internal interface for IDetailInternal and while looping through your collection of children, just cast them to IDetailInternal and invoke the internal methods.
I'll find that thread and edit my post w/ a link.
http://forums.lhotka.net/forums/thread/6832.aspx
And from another post:
So, what I found worked for me was to cast the object to the internal interface for the purpose of doing the Update/DeleteSelf/Insert.
((IProfileMemberInternal)profileMember).DeleteSelf();
Yes, that is the way to do it in VB.Net. To create an explicit interface in VB.NET you set the properties or methods to something other than public in the class that implements the interface. It is easier to create explicit interfaces in VB.Net than in C#.
malloc1024:It is easier to create explicit interfaces in VB.Net than in C#.
I didn’t mean to say that it was tough to create an explicit interface in C#, just slightly more work to remember how to create one. I find it easier to create explicit interfaces in VB.Net. But you are correct that it really isn’t more difficult. I do use VB.Net more and that may have something to do with my opinion.
I like the fact the interfaces are more explicit in VB.NET. I also find the way VB.NET handles explicit interfaces less confusing.
malloc1024:I didn’t mean to say that it was tough to create an explicit interface in C#, just slightly more work to remember how to create one. I find it easier to create explicit interfaces in VB.Net. But you are correct that it really isn’t more difficult. I do use VB.Net more and that may have something to do with my opinion.
malloc1024:I like the fact the interfaces are more explicit in VB.NET. I also find the way VB.NET handles explicit interfaces less confusing.
I'll agree that defining implicit interfaces is more explicit in VB than in C#. In C#, you don't need to do anything at all, the compiler just matches the signatures up and will say 'yup, I found something matching that interfaces signature, so the interface is implemented.'
You can use
EXPLICT interfaces to hide members of an interface. The only way to access the private or
protected members of an interface is to cast to the interface. If you place the interface in another
assembly, the presentation layer could not cast to it if it doesn’t have a
reference to it. One of the benefits of
using explicit interfaces is that it allows you to hide members of an interface.
Malloc, that's definitely correct. (Talked about a little bit in that first thread).
I would have taken that very route myself if it weren't for the fact that my child objects are generating insert/update/deleteself in partial classes and I didn't feel like manipulating the templates for generation yet. A generated internal method without an explicit implementation declaration throws a compile error.
Here's some sample code from one of my collections where I'm using reflection.
internal void Update(SqlConnection cn, IProfile parent){
RaiseListChangedEvents =
false; // loop through each deleted child object and use the internal interface // to call DeleteSelf for deleted objects foreach (IProfileRole deletedChild in DeletedList)deletedChild.GetType().InvokeMember(
"DeleteSelf", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, System.Type.DefaultBinder, deletedChild, new object[] { cn });DeletedList.Clear();
// loop through each non-deleted child object and use the internal interface // to call the appropriate method. foreach (IProfileRole child in this){
if (child.IsNew)child.GetType().InvokeMember(
"Insert", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, System.Type.DefaultBinder, child, new object[] { cn, parent }); elsechild.GetType().InvokeMember(
"Update", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod, System.Type.DefaultBinder, child, new object[] { cn, parent });}
RaiseListChangedEvents =
true;}
#endregion
//Data Access
Copyright (c) Marimer LLC