.NET Programming
--
Questions
--
Followers
Top Experts
C# Guid Extension Method
Greetings. Â I'm trying to create an extension method on System.Guid. Â The code compiles, but when i try to use it, the method is not availble. Â Here's the code and it compiles:
namespace Common.Utilities.GuidUtili ties
{
  public static class GuidExtensions
  {
    public static bool IsNullOrEmptyGuid(this Guid? guid)
    {
      bool isNullorEmptyGuid = false;
      if (guid == null || guid == Guid.Empty)
        isNullorEmptyGuid = true;
      return isNullorEmptyGuid;
    }
  }
}
So when i try to use the code: Â I include the namespace, but when I type System.Guid, method IsNullorEmptyGuid is not available.
Any help is appreciated. Â Thank you.
namespace Common.Utilities.GuidUtili
{
  public static class GuidExtensions
  {
    public static bool IsNullOrEmptyGuid(this Guid? guid)
    {
      bool isNullorEmptyGuid = false;
      if (guid == null || guid == Guid.Empty)
        isNullorEmptyGuid = true;
      return isNullorEmptyGuid;
    }
  }
}
So when i try to use the code: Â I include the namespace, but when I type System.Guid, method IsNullorEmptyGuid is not available.
Any help is appreciated. Â Thank you.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
ASKER CERTIFIED SOLUTION
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Extension methods apply to instance of a class and not the class itself.
E.g.
Guid? g = Guid.NewGuid();
g.IsNullOrEmptyGuid();
E.g.
Guid? g = Guid.NewGuid();
g.IsNullOrEmptyGuid();






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
.NET Programming
--
Questions
--
Followers
Top Experts
The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.