Eric Gagnon
Eric Gagnon

Reputation: 13

Dotnet core 2.1 extension method don't compile

I'm trying to create an extension method in a dotnet core 2.1 application and it does not compile.

My Extension method:

 public static class ObjectExtension
 {
    public static bool IsNull(this Object object)
    {
        return Object.ReferenceEquals(object, null);
    }
 }

Error output:

ObjectExtension.cs(7,47): error CS1001: Identifier expected ObjectExtension.cs(7,47): error CS1003: Syntax error, ',' expected ObjectExtension.cs(7,53): error CS1001: Identifier expected ObjectExtension.cs(9,43): error CS1525: Invalid expression term 'object'

Upvotes: 1

Views: 31

Answers (2)

Default Writer
Default Writer

Reputation: 2566

Add @ to object

    public static class ObjectExtension
    {
        public static bool IsNull(this Object @object)
        {
            return Object.ReferenceEquals(@object, null);
        }
    }

Upvotes: 0

Derviş Kayımbaşıoğlu
Derviş Kayımbaşıoğlu

Reputation: 30565

object is reserved word and cannot be used. please try to change it and compile again

Upvotes: 1

Related Questions