Why isn't there a Guid.IsNullOrEmpty() method

前端 未结 7 1350
不思量自难忘°
不思量自难忘° 2020-12-24 00:19

This keeps me wondering why Guid in .NET does not have IsNullOrEmpty() method (where empty means all zeros)

I need this at several places in my ASP.NET

7条回答
  •  星月不相逢
    2020-12-24 00:26

    Here is a generic extension class for nullable struct types:

    public static class NullableExtensions
    {
        public static bool IsNullOrDefault(this T? self) where T : struct
        {
            return !self.HasValue || self.Value.Equals(default(T));
        }
    }
    

提交回复
热议问题