Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to determine and check whether a type in assembly is Custom type or Primitive type using reflection in .NET?

How to determine and check whether a type in assembly is Custom type or Primitive type using reflection in .NET?

Scheduled Pinned Locked Moved C#
csharptutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    glitteringsound
    wrote on last edited by
    #1

    Hello, Is it possible to check at runtime whether given type is Custom data type or one of primitive data types of .NET? I have defined user defined types in assembly and those all types are some structs. I need to call the methods of user defined types of whome parameters are those structs. So this needs to fill the data accordingly before calling those function at runtime using reflection. Now Is there any method available in reflection by which we can track that given data type is custom or primitive data type. I know about IsClass attribute, but my targeted user defined data types are not classes , these public are STRUCTS. Regard

    N D P 3 Replies Last reply
    0
    • G glitteringsound

      Hello, Is it possible to check at runtime whether given type is Custom data type or one of primitive data types of .NET? I have defined user defined types in assembly and those all types are some structs. I need to call the methods of user defined types of whome parameters are those structs. So this needs to fill the data accordingly before calling those function at runtime using reflection. Now Is there any method available in reflection by which we can track that given data type is custom or primitive data type. I know about IsClass attribute, but my targeted user defined data types are not classes , these public are STRUCTS. Regard

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Perhaps I'm not getting your issue. If you need to call a method on your type then you need to verify it exists before attempting to call it so what does it matter if its an intrinsic .net type or not. Unless you have overridden methods your method won't exist.


      I know the language. I've read a book. - _Madmatt

      1 Reply Last reply
      0
      • G glitteringsound

        Hello, Is it possible to check at runtime whether given type is Custom data type or one of primitive data types of .NET? I have defined user defined types in assembly and those all types are some structs. I need to call the methods of user defined types of whome parameters are those structs. So this needs to fill the data accordingly before calling those function at runtime using reflection. Now Is there any method available in reflection by which we can track that given data type is custom or primitive data type. I know about IsClass attribute, but my targeted user defined data types are not classes , these public are STRUCTS. Regard

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        If the other assembly is a .Net dll, why not just add a reference and use the structs. Anyways, you can try IsValueType property if that helps. I am not 100% sure about what you are trying to do so the answer might not suite your needs.

        1 Reply Last reply
        0
        • G glitteringsound

          Hello, Is it possible to check at runtime whether given type is Custom data type or one of primitive data types of .NET? I have defined user defined types in assembly and those all types are some structs. I need to call the methods of user defined types of whome parameters are those structs. So this needs to fill the data accordingly before calling those function at runtime using reflection. Now Is there any method available in reflection by which we can track that given data type is custom or primitive data type. I know about IsClass attribute, but my targeted user defined data types are not classes , these public are STRUCTS. Regard

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          Maybe see if it's in the System namespace? Perhaps check to see if it's in a System Assembly? Perchance even access the Attributes of the Assembly to check the creator? But I don't think it would be 100% accurate. You could also compare it to a known built-in type; if the type says it's a System.Int32, compare it to the System.Int32 type. Just guessing, I haven't tried it.

          D 1 Reply Last reply
          0
          • P PIEBALDconsult

            Maybe see if it's in the System namespace? Perhaps check to see if it's in a System Assembly? Perchance even access the Attributes of the Assembly to check the creator? But I don't think it would be 100% accurate. You could also compare it to a known built-in type; if the type says it's a System.Int32, compare it to the System.Int32 type. Just guessing, I haven't tried it.

            D Offline
            D Offline
            dan sh
            wrote on last edited by
            #5

            PIEBALDconsult wrote:

            Maybe see if it's in the System namespace?

            I think a form object in the windows application gives namespace as the application namespace and notSystem.Windows.Forms. So I guess this won't work.

            P 1 Reply Last reply
            0
            • D dan sh

              PIEBALDconsult wrote:

              Maybe see if it's in the System namespace?

              I think a form object in the windows application gives namespace as the application namespace and notSystem.Windows.Forms. So I guess this won't work.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Riiight... that's kinda what I said. Custom types wouldn't (or shouldn't) be in the System namespace.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups