473,386 Members | 1,798 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,386 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 2034
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.