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. Other Discussions
  3. The Weird and The Wonderful
  4. If in doubt: cast, cast and cast again

If in doubt: cast, cast and cast again

Scheduled Pinned Locked Moved The Weird and The Wonderful
4 Posts 3 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.
  • M Offline
    M Offline
    Mardy Git
    wrote on last edited by
    #1

    My colleague found this and other horrors in a newish project. Bearing in mind that "Id" is a nullable int and result.ID is a regular int, who in their right mind would do this (object and function names have been changed to protect the incompetent):

    protected Thing populateThing(DataRow dr)
    {
    Thing result = new Thing();
    result.Id = int.Parse(dr["Id"].ToString());

    BTW, note no handling of the case when "Id" is DBNULL. You can stop laughing now.

    P Z 2 Replies Last reply
    0
    • M Mardy Git

      My colleague found this and other horrors in a newish project. Bearing in mind that "Id" is a nullable int and result.ID is a regular int, who in their right mind would do this (object and function names have been changed to protect the incompetent):

      protected Thing populateThing(DataRow dr)
      {
      Thing result = new Thing();
      result.Id = int.Parse(dr["Id"].ToString());

      BTW, note no handling of the case when "Id" is DBNULL. You can stop laughing now.

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

      And with what did you replace it?

      M 1 Reply Last reply
      0
      • P PIEBALDconsult

        And with what did you replace it?

        M Offline
        M Offline
        Mardy Git
        wrote on last edited by
        #3

        I didn't it's not my project. My colleague was traumatised by this and many other code-crimes in the project, I'm hoping he'll recover soon :laugh:

        1 Reply Last reply
        0
        • M Mardy Git

          My colleague found this and other horrors in a newish project. Bearing in mind that "Id" is a nullable int and result.ID is a regular int, who in their right mind would do this (object and function names have been changed to protect the incompetent):

          protected Thing populateThing(DataRow dr)
          {
          Thing result = new Thing();
          result.Id = int.Parse(dr["Id"].ToString());

          BTW, note no handling of the case when "Id" is DBNULL. You can stop laughing now.

          Z Offline
          Z Offline
          ZurdoDev
          wrote on last edited by
          #4

          I must be missing something. Doesn't dr["Id"] return an object?

          There are only 10 types of people in the world, those who understand binary and those who don't.

          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