No announcement yet.

Guid property does not equal default(Guid)

  • Filter
  • Time
  • Show
Clear All
new posts

    Guid property does not equal default(Guid)

    I believe that the following code demonstrates a bug:

    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)

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


      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:

      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:




        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,