473,499 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting the data type for a class field

I'm having trouble finding the right method to determine at runtime the data
type of the fields in a class.

here's what I've got so far:
Public Class ImgSubmissionRecord

Public fileName As String

Public thumbnail As Bitmap

Public fileSize As Int64

Public fileDate As DateTime

Public disposition As Int16

End Class

Imports System.Reflection

Public Class debugControl

Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected WithEvents lblDebug As System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form
Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: This method call is required by the Web Form Designer

'Do not modify it using the code editor.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim anObject As New ImgSubmissionRecord

Dim MemInfo, memInfoArray() As MemberInfo

Dim aType As Type = anObject.GetType

memInfoArray = aType.GetMembers(BindingFlags.Public Or
BindingFlags.Instance)

For Each MemInfo In memInfoArray

Me.lblDebug.Text = Me.lblDebug.Text + "<br>" + MemInfo.Name + "/" +
System.Type.GetType(MemInfo.GetType.ToString).ToSt ring

Next

End Sub

End Class

I get the name for each member of the class ok, but for the type I get

"System.Reflection.RuntimeFieldInfo"

instead of string or int16, or bitmap, or whatever type the member is. How
do I get this information at runtime?

-Larry


Nov 19 '05 #1
2 1165
Hi Larry:

On Wed, 5 Oct 2005 21:59:08 -0700, "Larry" <hu******@comcast.net>
wrote:
I'm having trouble finding the right method to determine at runtime the data
type of the fields in a class.

....

memInfoArray = aType.GetMembers(BindingFlags.Public Or
BindingFlags.Instance)


The problem is GetMembers will return fields and methods (all
members). Since methods don't have a type the MemberInfo objects don't
have a property to tell you the type of the member.

What you really want to use is GetFields, which returns an array of
FieldInfo. A FieldInfo object has a FieldType property, which can tell
you the type of the field (String, Int32, Hashtable, etc).

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/
Nov 19 '05 #2
Thanks. I'll give that a try.

-Larry

"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:9r********************************@4ax.com...
Hi Larry:

On Wed, 5 Oct 2005 21:59:08 -0700, "Larry" <hu******@comcast.net>
wrote:
I'm having trouble finding the right method to determine at runtime the
data
type of the fields in a class.


...

memInfoArray = aType.GetMembers(BindingFlags.Public Or
BindingFlags.Instance)


The problem is GetMembers will return fields and methods (all
members). Since methods don't have a type the MemberInfo objects don't
have a property to tell you the type of the member.

What you really want to use is GetFields, which returns an array of
FieldInfo. A FieldInfo object has a FieldType property, which can tell
you the type of the field (String, Int32, Hashtable, etc).

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

Nov 19 '05 #3

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

Similar topics

3
11735
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
5
2380
by: Carlos Ribeiro | last post by:
Hello all, I'm posting this to the list with the intention to form a group of people interested in this type of solution. I'm not going to spam the list with it, unless for occasional and...
3
2063
by: Sathyaish | last post by:
I wanted to practice some Linked List stuff, so I set out to create a linked list. The plan was to create the following: (1) A linked list class in Visual Basic (2) A non-class based linked list...
7
1802
by: WildHare | last post by:
If I have a class and I add it to an ArrayList and then want to access that class using using the index operator (e.g. ArrayList) the ArrayList returns a type "Object". I can cast the return to...
6
2023
by: Mike Hoff | last post by:
I am trying to write a class that will store info about database fields for building UPDATE / INSERT commands later on. I cannot seem to get the sytax correct to pass and store the data type of...
13
10085
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
0
2396
by: amrhi | last post by:
Hy Guys , Can anybody help me ? I try to make small web database in my unit. Some of fields have on change behaviour to get other data that automatically filled other text field. But when i try to...
22
6601
by: Sri | last post by:
All Recenetly our shop migrated to DB2 V8 from V7. We are in IBM System Level: z/OS 1.6.1 @ RSU 0702. Processor : IBM 2064-1C7 (z/900) # 1B89 Mode: 64-bit One of my application is facing...
10
2252
by: jonathan184 | last post by:
Hi I tried getting this to work through dreamweaver but it did not. So i found a n example on the internet , i followed everything exactly the search script does not work. Could somebody help me...
1
3962
by: SkipNRun | last post by:
I am a novice when comes to JavaScript, AJAX. I am working on a form, which will allow users to update their contact information. In order to make the form flexible, I need to use pull down list. ...
0
7178
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
7223
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4919
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.