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. C# properties and type safety

C# properties and type safety

Scheduled Pinned Locked Moved The Weird and The Wonderful
csharppythonquestion
9 Posts 7 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.
  • J Offline
    J Offline
    Julien Villers
    wrote on last edited by
    #1

    Apparently, my predecessor didn't trust in the C# typing system and... there's more that's wrong with this:

    [XmlIgnore]
    public DateTime? SomeProperty
    {
    get;set;
    }

    public String SomePropertyXml
    {
    get
    {
    return SomeProperty.HasValue ? XmlConvert.ToString(SomeProperty.Value) : null;
    }
    set
    {
    if (String.IsNullOrEmpty(value as String))
    SomeProperty = null;
    else
    SomeProperty = XmlConvert.ToTimeSpan(value);
    }
    }

    Oh, and I have removed identifiable identifiers, but I haven't removed any comments :-(

    'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail

    A B S 3 Replies Last reply
    0
    • J Julien Villers

      Apparently, my predecessor didn't trust in the C# typing system and... there's more that's wrong with this:

      [XmlIgnore]
      public DateTime? SomeProperty
      {
      get;set;
      }

      public String SomePropertyXml
      {
      get
      {
      return SomeProperty.HasValue ? XmlConvert.ToString(SomeProperty.Value) : null;
      }
      set
      {
      if (String.IsNullOrEmpty(value as String))
      SomeProperty = null;
      else
      SomeProperty = XmlConvert.ToTimeSpan(value);
      }
      }

      Oh, and I have removed identifiable identifiers, but I haven't removed any comments :-(

      'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail

      A Offline
      A Offline
      Andrei Straut
      wrote on last edited by
      #2

      Apparently this was written before the Big Bang when the concept of time didn't exist, thus the need for a nullable DateTime property :wtf:

      Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

      J B 2 Replies Last reply
      0
      • A Andrei Straut

        Apparently this was written before the Big Bang when the concept of time didn't exist, thus the need for a nullable DateTime property :wtf:

        Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

        J Offline
        J Offline
        Julien Villers
        wrote on last edited by
        #3

        Oh, that's not even strange in my codebase. We have many nullable DateTime, as optional parameters/informations. For instance, we have a kind of 'last access date' for files, which is stored as a Nullable.

        'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail

        L 1 Reply Last reply
        0
        • J Julien Villers

          Apparently, my predecessor didn't trust in the C# typing system and... there's more that's wrong with this:

          [XmlIgnore]
          public DateTime? SomeProperty
          {
          get;set;
          }

          public String SomePropertyXml
          {
          get
          {
          return SomeProperty.HasValue ? XmlConvert.ToString(SomeProperty.Value) : null;
          }
          set
          {
          if (String.IsNullOrEmpty(value as String))
          SomeProperty = null;
          else
          SomeProperty = XmlConvert.ToTimeSpan(value);
          }
          }

          Oh, and I have removed identifiable identifiers, but I haven't removed any comments :-(

          'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail

          B Offline
          B Offline
          BillW33
          wrote on last edited by
          #4

          Clearly your predecessor did not understand either the type system nor TimeSpans. :wtf:

          Just because the code works, it doesn't mean that it is good code.

          B 1 Reply Last reply
          0
          • B BillW33

            Clearly your predecessor did not understand either the type system nor TimeSpans. :wtf:

            Just because the code works, it doesn't mean that it is good code.

            B Offline
            B Offline
            Brisingr Aerowing
            wrote on last edited by
            #5

            Likely both.

            I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We've created life in our own image. Stephen Hawking

            1 Reply Last reply
            0
            • J Julien Villers

              Oh, that's not even strange in my codebase. We have many nullable DateTime, as optional parameters/informations. For instance, we have a kind of 'last access date' for files, which is stored as a Nullable.

              'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You don't access it on creation? Show me, how do I bake a cake without touching it? ;P

              Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

              J 1 Reply Last reply
              0
              • A Andrei Straut

                Apparently this was written before the Big Bang when the concept of time didn't exist, thus the need for a nullable DateTime property :wtf:

                Full-fledged Java/.NET lover, full-fledged PHP hater. Full-fledged Google/Microsoft lover, full-fledged Apple hater. Full-fledged Skype lover, full-fledged YM hater.

                B Offline
                B Offline
                BobJanova
                wrote on last edited by
                #7

                Makes sense to me ... if you don't know what date something happened on, or if it didn't happen yet, both of which are quite common.

                1 Reply Last reply
                0
                • L Lost User

                  You don't access it on creation? Show me, how do I bake a cake without touching it? ;P

                  Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

                  J Offline
                  J Offline
                  Julien Villers
                  wrote on last edited by
                  #8

                  Ok, I'll be more precise then. I'm working on a media player application, in which you get a list of media files from a webservice. The DateTime of last playback is null until you have actually played the file. Does that make sense now?

                  'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail

                  1 Reply Last reply
                  0
                  • J Julien Villers

                    Apparently, my predecessor didn't trust in the C# typing system and... there's more that's wrong with this:

                    [XmlIgnore]
                    public DateTime? SomeProperty
                    {
                    get;set;
                    }

                    public String SomePropertyXml
                    {
                    get
                    {
                    return SomeProperty.HasValue ? XmlConvert.ToString(SomeProperty.Value) : null;
                    }
                    set
                    {
                    if (String.IsNullOrEmpty(value as String))
                    SomeProperty = null;
                    else
                    SomeProperty = XmlConvert.ToTimeSpan(value);
                    }
                    }

                    Oh, and I have removed identifiable identifiers, but I haven't removed any comments :-(

                    'I'm French! Why do you think I've got this outrrrrageous accent?' Monty Python and the Holy Grail

                    S Offline
                    S Offline
                    SimulationofSai
                    wrote on last edited by
                    #9

                    I've seen stranger DateTime usage in the Web Service I'm working on. We use a nullable type too, but in this case it was a WTF because Microsoft handed us a WTF with WCF. Stranger is our code that handles a DataSet which has a DateTime column as part of an incoming web request. Whenever we get new developers on board, we watch them when they come across this piece of code. Some of them slump down in their desks and go into a trance, while some quickly walk away and wash their hands with plenty of SOAP. :)

                    SG Aham Brahmasmi!

                    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