Link to home
Create AccountLog in
.NET Programming

.NET Programming

--

Questions

--

Followers

Top Experts

Avatar of allenanderson
allenanderson🇺🇸

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.GuidUtilities
{
    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.
User generated imageAny 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
Avatar of Meir RivkinMeir Rivkin🇮🇱

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of hemantkshhemantksh🇮🇳

Extension methods apply to instance of a class and not the class itself.

E.g.
Guid? g = Guid.NewGuid();
g.IsNullOrEmptyGuid();

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.

.NET Programming

.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.