System.Type - structure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Qwert

    #1

    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.


  • Mike Labosh

    #2
    Re: System.Type - structure

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

    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"


    Comment

    • Armin Zingler

      #3
      Re: System.Type - structure

      "Mike Labosh" <mlabosh@hotmai l.com> schrieb[color=blue][color=green]
      > > 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?[/color]
      >
      > 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:[/color]


      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

      Comment

      • Qwert

        #4
        Re: System.Type - structure

        Indeed, that is my question. And the answer is?
        [color=blue]
        > ...
        > 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[/color]


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: System.Type - structure

          "Qwert" <nosp@nosp.co m> schrieb:[color=blue]
          > Indeed, that is my question. And the answer is?
          >[color=green]
          >> 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).[/color][/color]

          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/>

          Comment

          • Jay B. Harlow [MVP - Outlook]

            #6
            Re: System.Type - structure

            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" <nosp@nosp.co m> wrote in message
            news:UL2dnbPg4s RSCV_fRVnyjA@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
            |
            |


            Comment

            • Qwert

              #7
              Re: System.Type - structure

              "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]" <hirf-spam-me-here@gmx.at> schreef in bericht
              news:eKR7GgKfFH A.3912@tk2msftn gp13.phx.gbl...[color=blue]
              > "Qwert" <nosp@nosp.co m> schrieb:[color=green]
              >> Indeed, that is my question. And the answer is?
              >>[color=darkred]
              >>> 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).[/color][/color]
              >
              > 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/>[/color]


              Comment

              • Jay B. Harlow [MVP - Outlook]

                #8
                Re: System.Type - structure

                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" <nosp@nosp.co m> wrote in message
                news:kJWdnQtjCe AIOV_fRVnygg@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]" <hirf-spam-me-here@gmx.at> schreef in bericht
                | news:eKR7GgKfFH A.3912@tk2msftn gp13.phx.gbl...
                | > "Qwert" <nosp@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/>
                |
                |


                Comment

                • Armin Zingler

                  #9
                  Re: System.Type - structure

                  "Qwert" <nosp@nosp.co m> schrieb[color=blue]
                  > "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?[/color]


                  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

                  Comment

                  • Qwert

                    #10
                    Re: System.Type - structure

                    > | Yes, but a primitive type is a value type too but not a structure, so[color=blue]
                    > Odd! Every thing I've read on .NET has indicated the opposite, that Int32
                    > is
                    > a primitive type & that Int32 is a Structure.[/color]

                    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?"
                    [color=blue]
                    > 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.[/color]

                    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.
                    [color=blue]
                    > Hope this helps
                    > Jay[/color]

                    It does. Thanks everyone.


                    Comment

                    • Jay B. Harlow [MVP - Outlook]

                      #11
                      Re: System.Type - structure

                      Qwert,
                      | 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.
                      You can use Type.GetPropert ies to get the list of public properties
                      (System.Reflect ion.PropertyInf o), then use PropertyInfo.Ge tValue &
                      PropertyInfo.Se tValue to get or set the value of said property.

                      Something like:

                      Imports System.Reflecti on

                      Dim something As SomeType

                      Dim properties() As PropertyInfo =
                      something.GetTy pe().GetPropert ies()

                      For Each pi As PropertyInfo In properties
                      Debug.WriteLine (pi.GetValue(so mething, Nothing))
                      Next

                      For Each pi As PropertyInfo In properties
                      dim value as Object = ...
                      pi.SetValue(som ething, value, Nothing)
                      Next



                      Alternatively you can use System.Componen tModel.Property Descriptor in a
                      similar manor, something like:

                      Imports System.Componen tModel

                      Dim something As SomeType

                      Dim properties As PropertyDescrip torCollection =
                      TypeDescriptor. GetProperties(s omething)

                      For Each pd As PropertyDescrip tor In properties
                      Debug.WriteLine (pd.GetValue(so mething))
                      Next

                      For Each pd As PropertyDescrip tor In properties
                      dim value as Object = ...
                      pd.SetValue(som ething, value)
                      Next

                      Seeing as Primitives & Enums don't have public instance properties, the
                      above code will not return any properties...

                      Hope this helps
                      Jay

                      "Qwert" <nosp@nosp.co m> wrote in message
                      news:2MmdnUWvDL inL1_fRVnyjA@ca sema.nl...
                      |> | 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.
                      |
                      |


                      Comment

                      Working...