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. Checking for empty guid

Checking for empty guid

Scheduled Pinned Locked Moved The Weird and The Wonderful
20 Posts 8 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.
  • S Stepan Kobzey

    Thats how one of our developers with 18 years experience checks if guid is empty

    public List GetCommentIdsByUserQueryID_Paging(Guid userQueryID, out int total, int skipCount = 0, int itemsPerPage = 20)
            {
    .........
                 if (userQueryID.ToString().Length==0) return null;
    ..........

    Sander RosselS Offline
    Sander RosselS Offline
    Sander Rossel
    wrote on last edited by
    #5

    Should have been:

    if (userQueryID.ToString() == "00000000-0000-0000-0000-000000000000") return null;

    He should've known that :D Alternatively he could've looped and count the 0's. Just don't use Guid.Empty. I heard it's bugged :~

    It's an OO world.

    public class SanderRossel : Lazy<Person>
    {
    public void DoWork()
    {
    throw new NotSupportedException();
    }
    }

    P OriginalGriffO 2 Replies Last reply
    0
    • Sander RosselS Sander Rossel

      Should have been:

      if (userQueryID.ToString() == "00000000-0000-0000-0000-000000000000") return null;

      He should've known that :D Alternatively he could've looped and count the 0's. Just don't use Guid.Empty. I heard it's bugged :~

      It's an OO world.

      public class SanderRossel : Lazy<Person>
      {
      public void DoWork()
      {
      throw new NotSupportedException();
      }
      }

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

      What if it has lower-case zeroes? :-D

      You'll never get very far if all you do is follow instructions.

      Sander RosselS 1 Reply Last reply
      0
      • Sander RosselS Sander Rossel

        Should have been:

        if (userQueryID.ToString() == "00000000-0000-0000-0000-000000000000") return null;

        He should've known that :D Alternatively he could've looped and count the 0's. Just don't use Guid.Empty. I heard it's bugged :~

        It's an OO world.

        public class SanderRossel : Lazy<Person>
        {
        public void DoWork()
        {
        throw new NotSupportedException();
        }
        }

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #7

        Sander Rossel wrote:

        I heard it's bugged

        You heard right - it's not even slightly unique.

        Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        Sander RosselS 1 Reply Last reply
        0
        • S Stepan Kobzey

          Thats how one of our developers with 18 years experience checks if guid is empty

          public List GetCommentIdsByUserQueryID_Paging(Guid userQueryID, out int total, int skipCount = 0, int itemsPerPage = 20)
                  {
          .........
                       if (userQueryID.ToString().Length==0) return null;
          ..........

          J Offline
          J Offline
          JMK NI
          wrote on last edited by
          #8

          Why doesn't he just generate the same guid again and compare?

          B 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Sander Rossel wrote:

            I heard it's bugged

            You heard right - it's not even slightly unique.

            Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)

            Sander RosselS Offline
            Sander RosselS Offline
            Sander Rossel
            wrote on last edited by
            #9

            Isn't a non-unique GUID pretty unique :D

            It's an OO world.

            public class SanderRossel : Lazy<Person>
            {
            public void DoWork()
            {
            throw new NotSupportedException();
            }
            }

            P 1 Reply Last reply
            0
            • P PIEBALDconsult

              What if it has lower-case zeroes? :-D

              You'll never get very far if all you do is follow instructions.

              Sander RosselS Offline
              Sander RosselS Offline
              Sander Rossel
              wrote on last edited by
              #10

              You mean they aren't the letter O?

              It's an OO world.

              public class SanderRossel : Lazy<Person>
              {
              public void DoWork()
              {
              throw new NotSupportedException();
              }
              }

              1 Reply Last reply
              0
              • S Stepan Kobzey

                Thats how one of our developers with 18 years experience checks if guid is empty

                public List GetCommentIdsByUserQueryID_Paging(Guid userQueryID, out int total, int skipCount = 0, int itemsPerPage = 20)
                        {
                .........
                             if (userQueryID.ToString().Length==0) return null;
                ..........

                B Offline
                B Offline
                Bernhard Hiller
                wrote on last edited by
                #11

                Don't fix that! Other places using that function meanwhile rely on its "feature" that it returns a *special* list for Guid.Empty()!

                P 1 Reply Last reply
                0
                • J JMK NI

                  Why doesn't he just generate the same guid again and compare?

                  B Offline
                  B Offline
                  Bernhard Hiller
                  wrote on last edited by
                  #12

                  Exactly. Ought to be

                  Guid invalid = Guid.Empty();
                  if (userQueryID.ToString().ToUpper() != invalid.ToString().ToUpper());return null;

                  Oops;! Happened to add another feature...

                  P 1 Reply Last reply
                  0
                  • S Stepan Kobzey

                    Thats how one of our developers with 18 years experience checks if guid is empty

                    public List GetCommentIdsByUserQueryID_Paging(Guid userQueryID, out int total, int skipCount = 0, int itemsPerPage = 20)
                            {
                    .........
                                 if (userQueryID.ToString().Length==0) return null;
                    ..........

                    N Offline
                    N Offline
                    Nagy Vilmos
                    wrote on last edited by
                    #13

                    IIRC guid's are value not reference types so they can't be empty. Doesn't it have hasValue() method or some such?

                    Richard DeemingR 1 Reply Last reply
                    0
                    • N Nagy Vilmos

                      IIRC guid's are value not reference types so they can't be empty. Doesn't it have hasValue() method or some such?

                      Richard DeemingR Offline
                      Richard DeemingR Offline
                      Richard Deeming
                      wrote on last edited by
                      #14

                      They can't be null, but they can be empty, which is the guid equivalent of zero. http://msdn.microsoft.com/en-us/library/system.guid.empty.aspx[^] There's no HasValue property or method; you just need to test whether it's equal to Guid.Empty.


                      "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                      "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                      P 1 Reply Last reply
                      0
                      • Richard DeemingR Richard Deeming

                        They can't be null, but they can be empty, which is the guid equivalent of zero. http://msdn.microsoft.com/en-us/library/system.guid.empty.aspx[^] There's no HasValue property or method; you just need to test whether it's equal to Guid.Empty.


                        "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

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

                        Richard Deeming wrote:

                        you just need to test whether it's equal to Guid.Empty

                        Except for that you probably don't actually need to. Edit: I'm also suspicious as to whether or not they're actually using System.Guid. The snippet doesn't specify, so it's possible that they rolled their own Guid class and then all bets are off.

                        You'll never get very far if all you do is follow instructions.

                        Richard DeemingR 1 Reply Last reply
                        0
                        • P PIEBALDconsult

                          Richard Deeming wrote:

                          you just need to test whether it's equal to Guid.Empty

                          Except for that you probably don't actually need to. Edit: I'm also suspicious as to whether or not they're actually using System.Guid. The snippet doesn't specify, so it's possible that they rolled their own Guid class and then all bets are off.

                          You'll never get very far if all you do is follow instructions.

                          Richard DeemingR Offline
                          Richard DeemingR Offline
                          Richard Deeming
                          wrote on last edited by
                          #16

                          Well, you do if you want to know whether or not it's empty. ;P


                          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

                          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

                          P 1 Reply Last reply
                          0
                          • Richard DeemingR Richard Deeming

                            Well, you do if you want to know whether or not it's empty. ;P


                            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

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

                            Except you probably don't actually need to.

                            You'll never get very far if all you do is follow instructions.

                            1 Reply Last reply
                            0
                            • Sander RosselS Sander Rossel

                              Isn't a non-unique GUID pretty unique :D

                              It's an OO world.

                              public class SanderRossel : Lazy<Person>
                              {
                              public void DoWork()
                              {
                              throw new NotSupportedException();
                              }
                              }

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

                              Pretty much the same argument as that for "there are no uninteresting numbers". :thumbsup: "If there are uninteresting numbers, there must be a first uninteresting number, and that number would therefore be pretty interesting."

                              You'll never get very far if all you do is follow instructions.

                              1 Reply Last reply
                              0
                              • B Bernhard Hiller

                                Exactly. Ought to be

                                Guid invalid = Guid.Empty();
                                if (userQueryID.ToString().ToUpper() != invalid.ToString().ToUpper());return null;

                                Oops;! Happened to add another feature...

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

                                Is the errant semi-colon on purpose? :suss:

                                You'll never get very far if all you do is follow instructions.

                                1 Reply Last reply
                                0
                                • B Bernhard Hiller

                                  Don't fix that! Other places using that function meanwhile rely on its "feature" that it returns a *special* list for Guid.Empty()!

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

                                  Bernhard Hiller wrote:

                                  it returns a *special* list for Guid.Empty()!

                                  It's _expecte_d to, but does it?

                                  You'll never get very far if all you do is follow instructions.

                                  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