Announcement

Collapse
No announcement yet.

Guid property does not equal default(Guid)

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Guid property does not equal default(Guid)

    I believe that the following code demonstrates a bug:

    https://deck.net/c88ad8f4d889d8a83ad728ca5a4eb332

    In .NET any non-initialized Guid field/property will return true when compared to default(Guid). However, in the Bridge.NET implementation an uninitialized Guid field equals null. So as a workaround I can check:

    if (test.Id == null)

    #2
    You get the same results in bridge than in dot net:

    https://dotnetfiddle.net/SHvnvV

    Comment


      #3
      Hi emumanu
      Of course, sorry, I must have suffered from severe sleep deprivation when I posted my sample. It was wrong in two ways: I accidentally switched wrong/correct check, and I forgot the ObjectLiteral attribute:

      Check out the following sample: https://deck.net/7896053b5da7e3666ab5f19766d8523a

      This time Bridge breaks .NET behavior, and that's how I first encountered the problem. But looking at it from distance now, I guess this behavior is hard to avoid since plain JS objects don't really initialize anything. I solved the problem by simply checking: (test.Id == null || test.Id == default(Guid)). For anyone using Guids I recommend writing an extension method for this, just to be sure:

      test.Id.IsNullOrEmpty()

      Comment


        #4
        @Marco,

        don't worry. Been there, done that.

        I think you're right. In your example, if you change the ObjectLiteralAttribute to [ObjectLiteral(ObjectInitializationMode.DefaultValu e)] it works. However, using [ObjectLiteral(ObjectInitializationMode.DefaultValu e, ObjectCreateMode.Constructor)] it doesn't, and I think it should.

        Best regards,
        Manu

        Comment

        Working...
        X