Is it recommended practice to include extension method within the static class itself?
I have:
public static class DataManager
{
private s开发者_JAVA百科tatic Dictionary<string, DataTable> dataTables;
// extension method
public static DataTable GetTable ( this string TableName )
{
return dataTables[ TableName ];
}
}
I didn't want to expose the Dictionary collection, and this is the way I thought to accomplish this task. In my calling method:
DataTable GetTable (string TableName)
{
return TableName.GetTable();
}
Is there another way I should, or could do this? Or is this acceptable?
I don't think that this is a good idea because, your method does not operate on a string
(what the extension method would state), it operates on DataManager
. So just use a static method in this case.
精彩评论