I attempted to get all the members in an interface with the following code in VB
Imports System.Reflection
Module Module1
Sub Main()
Dim T = GetType(IDerived)
'List all the members available in IDerived
For Each member In T.GetMembers(BindingFlags.Public Or BindingFlags.Instance)
Console.WriteLine(member)
Next
End Sub
End Module
Interface IBase
Sub BaseMethod()
End Interface
Interface IDerived
Inherits IBase
Sub DerivedMethod()
End Interface
And expcected the output includes both BaseMethod
and DerivedMethod
.
However, I got only
Void DerivedMethod()
This is different from the behavior of GetMembers
that applied to a class Type, which will return all the derived members.
-
I'm curious why it is the case. I suspect it may be designed to avoid name collision or something.
-
And the most important, how to get the members decalared in base interfaces? I have a solution, that I can enumerate all the interfaces it derived from, and then invoke
GetMembers
one by one, but it seems rather tedious.
Aucun commentaire:
Enregistrer un commentaire