473,608 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I check the type of the value represented in a system.type?

Don
I have an array of System.type and I need to go through the array and
perform different logic depending on the type stored in the array.

I want to do:
if (typeof typeCollection( i) is String) then
'some logic
elseif (typeof typeCollection( i) is int32) then
'some logic
.....

The problem is the type of my object is always system.type. If I
toString it I get the text that represents the data type but I don't
really like string comparisions when I'm trying to determine type.

I am storing the type of data from a dataColumn in this array as
follows:
typeCollection. add(dataColumn. dataType())

I then add the array to the viewState so I can access the data after a
postback.

Thanks,
Don

Nov 19 '05 #1
5 1831
Don,

I think you need to store your items as an array of System.Object instead of
System.Type. Then when you check them you won't always get back System.Type.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Don" <ch*********@ho tmail.com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
I have an array of System.type and I need to go through the array and
perform different logic depending on the type stored in the array.

I want to do:
if (typeof typeCollection( i) is String) then
'some logic
elseif (typeof typeCollection( i) is int32) then
'some logic
....

The problem is the type of my object is always system.type. If I
toString it I get the text that represents the data type but I don't
really like string comparisions when I'm trying to determine type.

I am storing the type of data from a dataColumn in this array as
follows:
typeCollection. add(dataColumn. dataType())

I then add the array to the viewState so I can access the data after a
postback.

Thanks,
Don

Nov 19 '05 #2
Don
I have a DataTable filled with data from the database which I bind to
the datagrid. On post back I need to be able to determine the data
type for each cell on the selected row.

To do this I iterate through the columns in the data table and add the
type of each column to the array as shown below:
dim col as datacolumn

for each col in datatable.colum n
typeCollection. add(col.DataTyp e())
next

I can't add the column to the array because it is not serializable and
I need to store it in the ViewState. I don't have an actual object to
add to the array. I could iterate through the first row and add that
object to the array but I still need the DataTypes when I have no rows
returned.

Nov 19 '05 #3
Don,

Ahhhh, didn't know that. I think you could do this:

Going with what you said earlier about ToString working go ahead and store
each column type using ToString

typeCollection. add(col.DataTyp e().ToString)

But then when you do your comparison use the System.Type object's GetType
method.

If (System.Type.Ge tType(typeColle ction(i).toStri ng) Is String) Then

The System.Type.Get Type function returns a type based on the string name.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Don" <ch*********@ho tmail.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
I have a DataTable filled with data from the database which I bind to
the datagrid. On post back I need to be able to determine the data
type for each cell on the selected row.

To do this I iterate through the columns in the data table and add the
type of each column to the array as shown below:
dim col as datacolumn

for each col in datatable.colum n
typeCollection. add(col.DataTyp e())
next

I can't add the column to the array because it is not serializable and
I need to store it in the ViewState. I don't have an actual object to
add to the array. I could iterate through the first row and add that
object to the array but I still need the DataTypes when I have no rows
returned.

Nov 19 '05 #4
Don
This does not work. As you stated GetType returns a type based on the
string name and I already have that in the typeCollection in array.
The problem is that the type of this obejct is System.Type not
System.String so I can't do the typeOf operation.

Nov 19 '05 #5
Don,

Did you try it?

Works fine for me.

Here's the code I used, run it and see.

Dim DataTable1 As New DataTable

DataTable1.Colu mns.Add(New DataColumn("Col umn1", GetType(String) ))

DataTable1.Colu mns.Add(New DataColumn("Col umn2", GetType(Int32)) )

DataTable1.Colu mns.Add(New DataColumn("Col umn3", GetType(Object) ))

DataTable1.Colu mns.Add(New DataColumn("Col umn4", GetType(DateTim e)))

Dim ArrayList As New ArrayList

For Each Column As DataColumn In DataTable1.Colu mns

ArrayList.Add(C olumn.DataType. ToString)

Next

Dim ColumnCount, ColumnLoop As Int32

ColumnCount = ArrayList.Count - 1

Dim TypeString As String

For ColumnLoop = 0 To ColumnCount

If System.Type.Get Type(ArrayList( ColumnLoop).ToS tring) Is GetType(Int32)
Then

Response.Write( "Int32 Found in Column " & ColumnLoop.ToSt ring)

End If

Next
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Don" <ch*********@ho tmail.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
This does not work. As you stated GetType returns a type based on the
string name and I already have that in the typeCollection in array.
The problem is that the type of this obejct is System.Type not
System.String so I can't do the typeOf operation.

Nov 19 '05 #6

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

Similar topics

8
2236
by: Rade | last post by:
Following a discussion on another thread here... I have tried to understand what is actually standardized in C++ regarding the representing of integers (signed and unsigned) and their conversions. The reference should be 3.9.1 (Fundamental types), and 4.7 (Integral conversions). It seems to me that the Standard doesn't specify: 1) The "value representation" of any of these types, except that (3.9.1/3) "... The range of nonnegative...
7
1522
by: Starx | last post by:
I am writing a fraction class and I was testing my addition operator to find out how big the numerator and denominator can be before an overflow occurs. I was doing it like this: fraction frac1(10001, 10000); //Creates 10001/10000 cout << frac1 << " * 2 = " << frac1 + frac1 << endl; I then proceeded to add zero's to the first line and kept executing the program and looking for an obviously wrong result as an indication of overflow. ...
51
4494
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is there something wrong in there? -------------------------------------------------------------------- Types A type is a definition for a sequence of storage bits. It gives the meaning of the data stored in memory. If we say that the object a is an
4
7733
by: Stan R. | last post by:
Hello, I have xmllint and xsltproc installed and running on both my linux and win32 platforms, all seems good. I have a couple questions though. 1) If I have an external dtd file, which is included in my xml file, like <!DOCTYPE userlist SYSTEM "test.dtd">
7
9821
by: Harris | last post by:
Dear all, I have the following codes: ====== public enum Enum_Value { Value0 = 0, Value1 = 10,
11
3529
by: aisling.cronin | last post by:
Hi I am using ctime to convert the following string 1144412677847 .... Please could some one to double check if they get the same result as me (The Time is Sun Nov 02 09:11:51 2031). It seems incorrect and would like a second opion. #include <time.h> #include <stdio.h>
6
3392
by: Dan Henry | last post by:
I need a sanity check. The following is an exchange on comp.arch.embedded with CBFalconer in a rather long MISRA related thread. Since my little section of that thread and area of interest was never really about MISRA, but rather the one's complement representation of integer constant 0 and now how to zero memory portably, I am bringing the topic to this group. Try to ignore CBF's errors in the 1's complement -1 and sign magnitude -1...
4
3224
by: Giff | last post by:
Hi, I have a function that takes in a float and then performs a division. Since I know that it is impossible to check if the value I pass is equal to zero (being a float), I don't perform any check on that value. Now I doubt if this is a safe approach and ask for your advice. Thanks a lot in advance. /G
55
3284
by: lovecreatesbea... | last post by:
Do you check all error conditions for all library calls in you code? Is it necessary to check all errors? Is it convenient to check all errors (or how to make code clean and readable with mass of non business logic related code block)? The following code from net-snmp library calls atoi five times but checks none. Do we code a wrapper my_atoi_with_error_check() around atoi and call this new one everywhere else? Is it a good practice...
0
8057
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7998
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8491
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8470
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8329
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6010
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3959
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4022
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.