Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# How create a extension without parentheses

I have a weird question about C#.

I have a static class to store methods as extensions. Then, I have the following extension:

public static bool fwHasData(this DataTable table)
{
    return (table == null || table.Rows.Count == 0) ? true : false;
}

My question is: exists some way to avoid use the parentheses when I try to use the extension in my code?

Usage:

bool vHasData = MyDataTable.fwHasData(); // Works fine!

Expected usage:

bool vHasData = MyDataTable.fwHasData; // Removing the parentheses

Thanks a lot!

like image 298
MiBol Avatar asked Dec 25 '22 08:12

MiBol


1 Answers

This is not possible in C#. It would require some form of "extension property" syntax, which is not available in C#. It has been suggested in the past, but doesn't exist in the C# language today, nor in the upcoming C# 6 suggestions.

like image 62
Reed Copsey Avatar answered Jan 07 '23 19:01

Reed Copsey