473,804 Members | 3,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Type - structure

Hello,

is it correct that if a type (System.Type) is a value (.IsValueType=T rue)
and not primitive (.IsPrimitive=F alse), that type is a structure?

Thanks.
Nov 21 '05 #1
10 1924
> is it correct that if a type (System.Type) is a value (.IsValueType=T rue)
and not primitive (.IsPrimitive=F alse), that type is a structure?


Easy enough to find out.

*Every* developer should have a dummy VS.NET Solution called Hacks or Tests
or something that looks like this:

Hacks.sln
DBHacks.dbp
VBConsole.vbpro j
VBWindows.vbPro j
VBWebHacks.vbPr oj
CSConsole.cspro j
JSWindows.vbPro j

(you get the idea)

It took me less than five minutes to add a structure definition, test method
and modify my Sub Main() in VBConsole:
-----------------------------------------------
Module Module1

' This is the Module1.vb I got from creating a VB Console Application
' so I can experiment with stuff without having other form related
' stuff getting in the way of my attention span.

Private Structure Item
Public Field1 As String
Public Field2 As String
End Structure

Sub Main()

whatType()

Console.WriteLi ne(vbCrLf & "Press a key to exit.")
Console.ReadLin e()

End Sub

Private Sub whatType()

Dim x As Item

x.Field1 = "This"
x.Field1 = "That"

Console.WriteLi ne("IsValueTyp e = " & x.GetType().IsV alueType.ToStri ng())
Console.WriteLi ne("IsPrimitiv e = " & x.GetType().IsP rimitive.ToStri ng())

End Sub

' Lots of other test methods for other experiment's I've done

End Module

--
Peace & happy computing,

Mike Labosh, MCSD

"Mr. McKittrick, after very careful consideration, I have
come to the conclusion that this new system SUCKS."
-- General Barringer, "War Games"
Nov 21 '05 #2
"Mike Labosh" <ml*****@hotmai l.com> schrieb
is it correct that if a type (System.Type) is a value
(.IsValueType=T rue) and not primitive (.IsPrimitive=F alse), that
type is a structure?


Easy enough to find out.

*Every* developer should have a dummy VS.NET Solution called Hacks
or Tests or something that looks like this:

Hacks.sln
DBHacks.dbp
VBConsole.vbpro j
VBWindows.vbPro j
VBWebHacks.vbPr oj
CSConsole.cspro j
JSWindows.vbPro j

(you get the idea)

It took me less than five minutes to add a structure definition,
test method and modify my Sub Main() in VBConsole:

I think "Qwert"'s question was not how to get these properties but if the
value combination IsValueType=tru e and isprimitive=fal se is the guarantee
that the type is a structure (or if there are other properties that must be
taken into account).
Armin

Nov 21 '05 #3
Indeed, that is my question. And the answer is?
...
I think "Qwert"'s question was not how to get these properties but if the
value combination IsValueType=tru e and isprimitive=fal se is the guarantee
that the type is a structure (or if there are other properties that must
be taken into account).
Armin

Nov 21 '05 #4
"Qwert" <no**@nosp.co m> schrieb:
Indeed, that is my question. And the answer is?
I think "Qwert"'s question was not how to get these properties but if the
value combination IsValueType=tru e and isprimitive=fal se is the guarantee
that the type is a structure (or if there are other properties that must
be taken into account).


Did you already read the "Remarks" section of the 'Type.IsValueTy pe'
documentation?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
Qwert,
In addition to the other comments.

The way I see it if IsValueType = True & IsEnum = False you have a
Structure, as Int32 is a Structure, but an Enum is not a Structure per se.

Int32 is a special case Structure in that IsPrimitive=Tru e, however
IsPrimitive=Tru e does not diminish the fact that Int32 is also a structure.

Remember that Structures inherit directly from System.ValueTyp e. Although
System.Enum inherits from System.ValueTyp e it is a Class, as the defined
Enums themselves are the Value types, I would not consider the defined Enums
as Structures per se, as they are Enums. However! Based on the requirements
of what I am attempting to do I would consider, considering Enums as
Structures also as they are Value types!

Hope this helps
Jay

"Qwert" <no**@nosp.co m> wrote in message
news:UL******** ************@ca sema.nl...
| Indeed, that is my question. And the answer is?
|
| > ...
| > I think "Qwert"'s question was not how to get these properties but if
the
| > value combination IsValueType=tru e and isprimitive=fal se is the
guarantee
| > that the type is a structure (or if there are other properties that must
| > be taken into account).
| >
| >
| > Armin
|
|
Nov 21 '05 #6
"Value types are those that are represented as sequences of bits; value
types are not classes or interfaces. These are referred to as "structs" in
some programming languages."

Yes, but a primitive type is a value type too but not a structure, so
checking 'IsValueType=Tr ue' does not automaticly mean that it is a
structure. So that is why I check 'IsPrimitive=Fa lse'.
But now I wonder if there are more things I should check?

'ValueType=True ' can be:
Primitive type.
Structure.
Enum ('Type.IsEnum' for that)
Anything else?

Thanks.
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> schreef in bericht
news:eK******** ******@tk2msftn gp13.phx.gbl...
"Qwert" <no**@nosp.co m> schrieb:
Indeed, that is my question. And the answer is?
I think "Qwert"'s question was not how to get these properties but if
the value combination IsValueType=tru e and isprimitive=fal se is the
guarantee that the type is a structure (or if there are other properties
that must be taken into account).


Did you already read the "Remarks" section of the 'Type.IsValueTy pe'
documentation?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #7
Qwert,
| Yes, but a primitive type is a value type too but not a structure, so
Odd! Every thing I've read on .NET has indicated the opposite, that Int32 is
a primitive type & that Int32 is a Structure.

It sounds like you really need to decide what a "Structure" in the context
of your project is first, possibly without looking at the Type class. Then
we can take *your* definition of what a Structure is & possibly apply it to
the Type class.

Hope this helps
Jay
"Qwert" <no**@nosp.co m> wrote in message
news:kJ******** ************@ca sema.nl...
| "Value types are those that are represented as sequences of bits; value
| types are not classes or interfaces. These are referred to as "structs" in
| some programming languages."
|
| Yes, but a primitive type is a value type too but not a structure, so
| checking 'IsValueType=Tr ue' does not automaticly mean that it is a
| structure. So that is why I check 'IsPrimitive=Fa lse'.
| But now I wonder if there are more things I should check?
|
| 'ValueType=True ' can be:
| Primitive type.
| Structure.
| Enum ('Type.IsEnum' for that)
| Anything else?
|
| Thanks.
|
|
| "Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> schreef in bericht
| news:eK******** ******@tk2msftn gp13.phx.gbl...
| > "Qwert" <no**@nosp.co m> schrieb:
| >> Indeed, that is my question. And the answer is?
| >>
| >>> I think "Qwert"'s question was not how to get these properties but if
| >>> the value combination IsValueType=tru e and isprimitive=fal se is the
| >>> guarantee that the type is a structure (or if there are other
properties
| >>> that must be taken into account).
| >
| > Did you already read the "Remarks" section of the 'Type.IsValueTy pe'
| > documentation?
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|
Nov 21 '05 #8
"Qwert" <no**@nosp.co m> schrieb
"Value types are those that are represented as sequences of bits;
value types are not classes or interfaces. These are referred to as
"structs" in some programming languages."

Yes, but a primitive type is a value type too but not a structure,
so checking 'IsValueType=Tr ue' does not automaticly mean that it is
a structure. So that is why I check 'IsPrimitive=Fa lse'.
But now I wonder if there are more things I should check?

'ValueType=True ' can be:
Primitive type.
Structure.
Enum ('Type.IsEnum' for that)
Anything else?

No answer, but maybe helpful: Have a look at "Partition I Architecture.do c"
in the directory "Microsoft Visual Studio .NET 2003\SDK\v1.1\T ool Developers
Guide\docs". On page 31, there is a picture about the type system.

Armin

Nov 21 '05 #9
> | Yes, but a primitive type is a value type too but not a structure, so
Odd! Every thing I've read on .NET has indicated the opposite, that Int32
is
a primitive type & that Int32 is a Structure.
Aha, yes I did not know that (allthought indeed it clearly says so).

The documentation says:
"A structure is a generalization of the user-defined type (UDT) supported by
previous versions of Visual Basic."
Reading this made me to believe that primitive types are not structures.

Anyways, this means my question is wrong, it should have been (I think):

"is it correct that if a type (System.Type) is a value (.IsValueType=T rue)
and not primitive (.IsPrimitive=F alse) and not a enum (.IsEnum=False) , that
type is a composite data type?"
It sounds like you really need to decide what a "Structure" in the context
of your project is first, possibly without looking at the Type class. Then
we can take *your* definition of what a Structure is & possibly apply it
to
the Type class.
What I need to do is get and store the values of all public properties of
any class or structure..euhm ...I mean composite data type, which is no
problem. Somewhere in the process my question appeared.
Hope this helps
Jay


It does. Thanks everyone.
Nov 21 '05 #10

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

Similar topics

4
272
by: Pram | last post by:
I am curious why did Microsoft write System.DateTime as a structure instead of a class? Maybe for backward compatibilty with any existing old code? FYI, one of the differences between structure and class is we can set the structure to Nothing.
1
5996
by: gregory_may | last post by:
This code seems to "work" but I get the following errors: An unhandled exception of type 'System.NullReferenceException' occurred in system.windows.forms.dll then this one: An unhandled exception of type 'System.ExecutionEngineException' occurred in system.windows.forms.dll Anyone know how to either trap these errors or prevent them from happening?
5
451
by: Andre | last post by:
I have two questions; 1) When executing the sub routine "TestStructure", I'm trying to update the member "intTyres" in the structure "structureCar" dynamically using System.Reflection. The code executes, but the value does not change, nor is there an exception thrown. 2) Read comments in sub routine "TestIntegerProperty"
4
12022
by: audipen | last post by:
I have a problem with System.Type.GetType method. If you try out the following code in C# console app .. System.Type t = System.Type.GetType("System.DateTime"); System.Type t1 = System.Type.GetType("DateTime"); t is set to the appropriate Type object but the second call returns null (when I dont specify the namespace name)
6
22230
by: William Mild | last post by:
I must be getting brain fried. I can't see the error. Create a new web form with the following code begind: Public Class test Inherits System.Web.UI.Page Public Class ReportCardData Public Structure Attend Dim DaysTardy As Double
2
1663
by: Fredrik Melin | last post by:
Is there any way to extend or write a own "System.Decimal"? In the doc its declared as <Serializable> Public Structure Decimal Implements IFormattable, IComparable, IConvertibleBut how do you get the functionallity that you can do Dim x as mydecimalx = 100Is that possible or can only microsoft do stuff like that?RegardsFredrik
4
6930
by: Stofdeel | last post by:
Heya, I am looking for information about the System.RuntimeType and other Runtime classes. They are undocumented in my version of Visual Studio. So far I have no luck with internet, only some remarks: - All .NET classes are instances of System.RuntimeType. - RuntimeType is the basic Type object representing classes as found in the system.
669
26268
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
6
10381
by: =?Utf-8?B?SGFyZHkgV2FuZw==?= | last post by:
Hi guys, what does "default" here mean? What is the MSDN Library Help URL related to this explanation? -- Regards Hardy
0
9710
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
10085
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
7626
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
6858
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
5527
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
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4304
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 we have to send another system
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3000
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.