Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

question on inheritance of interfaces..

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
parez - 05 Mar 2008 22:52 GMT
I have interface IAbc,IDef

and  interface  IXyz inherits/implements(what is the right word) IAbc
and IDef

if  i  reflect the type IXyz it only shows me the members of IXyz and
not IAbc and IDef.

Why?

TIA
chrisrock2@gmail.com - 06 Mar 2008 01:18 GMT
>   I have interface IAbc,IDef
>
[quoted text clipped - 7 lines]
>
> TIA

Let me see if I understand this:
You have an interface named IXYZ that implements IABC and IDef

public interface IABC
{
  void MethodFromABC();
}

public interface IDef
{
  void MethodFromIDef();
}

public inteface IXYZ : IDef, IABC
{
   void MethodFromIXYZ();
}

Running reflection against IXY only returns MethodFromIXYZ()?

Is that correct?
parez - 06 Mar 2008 14:18 GMT
On Mar 5, 8:18 pm, chrisro...@gmail.com wrote:

> >   I have interface IAbc,IDef
>
[quoted text clipped - 32 lines]
>
> Is that correct?

Correct...
Ben Voigt [C++ MVP] - 06 Mar 2008 14:43 GMT
>  I have interface IAbc,IDef
>
[quoted text clipped - 5 lines]
>
> Why?

Because you didn't use BindingFlags.FlattenHierarchy

> TIA
parez - 06 Mar 2008 15:08 GMT
> >  I have interface IAbc,IDef
>
[quoted text clipped - 9 lines]
>
> > TIA

can you please shed some more light on it..
Ben Voigt [C++ MVP] - 06 Mar 2008 15:31 GMT
>>>  I have interface IAbc,IDef
>>
[quoted text clipped - 11 lines]
>
> can you please shed some more light on it..

Actually, it looks like BindingFlags.FlattenHierarchy is only needed for
static members (which interfaces don't have), sorry about that.
Type.GetMethods specifically guarantees that non-static members of a base
class are returned, but doesn't mention interfaces.  You can always iterate
though the interfaces returned by Type.GetInterfaces, though, to find the
interface members.
chrisrock2@gmail.com - 06 Mar 2008 15:38 GMT
> > >  I have interface IAbc,IDef
>
[quoted text clipped - 13 lines]
>
> - Show quoted text -

I don't think FlattenHierarchy works with interfaces. Found this on
the MSDN boards:

       ShowInterfaceMethods(typeof(myInterface));

       ShowInterfaceMethods(Type iType)
       {

           foreach (MethodInfo mi in
iType.GetMethods(BindingFlags.Public | BindingFlags.Instance |
BindingFlags.FlattenHierarchy))
           {

               Console.Writeline(mi.Name);
           }

           foreach (Type IBase in iType.GetInterfaces())
           {

               GetInterfaceMethods(IBase);

           }

       }
parez - 06 Mar 2008 21:19 GMT
> > >  I have interface IAbc,IDef
>
[quoted text clipped - 11 lines]
>
> can you please shed some more light on it..

Thanks both.. .I got what i wanted..

But is there a reason why I have to do that? Is it an oversight on ms
side?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.