473,395 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Reflection problem

Hi,
I try to use reflection to retrieve class B members and not inherited
members. I wonder why the myMember value is nothing. Any suggestions?

Thanks
Module Module1

Sub Main()
Dim myClass As B = New B
Dim myMembers As System.Reflection.MemberInfo() =
myClass.GetType.GetMembers(Reflection.BindingFlags .DeclaredOnly)

End Sub

End Module

Class A
Public a1 As Integer
Public a2 As Integer
End Class

Class B
Inherits A

Public b1 As Integer
End Class
Nov 21 '05 #1
2 2035
Read the Note on this page in the MSDN Documentation:
http://msdn.microsoft.com/library/de...classtopic.asp

<quote>
You must specify Instance or Static along with Public or NonPublic or no
members will be returned.
</quote>

So your call should look like:
Dim myMembers As System.Reflection.MemberInfo() = _
myClass.GetType.GetMembers( _
Reflection.BindingFlags.Public _
Or Reflection.BindingFlags.Instance _
Or Reflection.BindingFlags.DeclaredOnly)

hope that helps..
Imran.

"Marco" <ma***@support.endurance.it> wrote in message
news:8b******************@tornado.fastwebnet.it...
Hi,
I try to use reflection to retrieve class B members and not inherited
members. I wonder why the myMember value is nothing. Any suggestions?

Thanks
Module Module1

Sub Main()
Dim myClass As B = New B
Dim myMembers As System.Reflection.MemberInfo() =
myClass.GetType.GetMembers(Reflection.BindingFlags .DeclaredOnly)

End Sub

End Module

Class A
Public a1 As Integer
Public a2 As Integer
End Class

Class B
Inherits A

Public b1 As Integer
End Class

Nov 21 '05 #2
Marco,
Because "BindingFlags.DeclaredOnly" is "used to change how the search
works", which means you need to include other BindingFlags to actually
define the search, such as BindingFlags.Public to include public members,
also you need at least BindingFlags.Instance or BindingFlags.Static to say
if you want instance members or include Shared members also...

Try something like:
Dim flags As BindingFlags = BindingFlags.Instance _
Or BindingFlags.Public _
Or BindingFlags.DeclaredOnly
Dim myMembers As System.Reflection.MemberInfo()
=myClass.GetType.GetMembers(flags)

For details see:
http://msdn.microsoft.com/library/de...bersTopic2.asp

Hope this helps
Jay

"Marco" <ma***@support.endurance.it> wrote in message
news:8b******************@tornado.fastwebnet.it...
Hi,
I try to use reflection to retrieve class B members and not inherited
members. I wonder why the myMember value is nothing. Any suggestions?

Thanks
Module Module1

Sub Main()
Dim myClass As B = New B
Dim myMembers As System.Reflection.MemberInfo() =
myClass.GetType.GetMembers(Reflection.BindingFlags .DeclaredOnly)

End Sub

End Module

Class A
Public a1 As Integer
Public a2 As Integer
End Class

Class B
Inherits A

Public b1 As Integer
End Class

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Tim Werth | last post by:
I am trying to use reflection to add an event handler for the RowUpdated event of the OracleDataAdapter object (ODP.NET), but the same thing can be said for SqlDataAdapter if you only use...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
2
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray...
2
by: Lev | last post by:
Hi, I have some code that does reflection on an assembly I load. When I try to get the attributes on one of the methods implemented in the assembly, the MC++ version does not return anything....
3
by: HL | last post by:
The requirement is to send some information to other objects. The objects to whom the information has to be sent is not available at compile time. The names of the types (objects) will be provided...
7
by: Paul Hadfield | last post by:
Hi, I'm running into one problem with trying to call "Type.GetCustomAttributes(...)" on my reflected code. Basically - I can't trap my own custom attribute - I can only catch / identify system...
5
by: Klaudiusz Bryja | last post by:
Hi, This is for NetCF 2.0. I need to create event handling code which using reflection. I have some parameters in XML which describe how event should be handled. I have code to create...
6
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.