Total .NET Analyzer Rule Documentation  

EmptyMemberBody Rule

There is no code in the member body.

Remarks

The member body has no code, and therefore it will not do anything when the code executes. Although having empty member bodies has no effect on code execution, you should examine all empty members for the following potential issues:

1. The empty member could contain commented out code that you actually need. For example, the following code sample shows a subroutine where an essential line of code has been commented out (possibly for development or debugging purposes):


' VB
Sub DeleteLockFile
' Be sure to delete the lock file before exiting
' the application, or it won't ever start again.
' System.IO.File.Delete("LockFile.dat")
End Sub

// C#
public static void DeleteLockFile()
{
// Be sure to delete the lock file before exiting
// the application, or it won't ever start again.
// System.IO.File.Delete("LockFile.dat");
}


2. The empty member may represent undone work. For example, the following code sample shows where an empty function is being used as a placeholder for work that needs to be done, but has not yet been implemented:

' VB
Function ValidateCustomer() As Boolean
' TODO: very important - implement this before we deploy
End Function

// C#
public static bool ValidateCustomer()
{
// TODO: very important - implement this before we deploy
return true;
}

Resolution

Examine any methods, properties, functions, and other member types that do not represent undone work or code that needs to be uncommented. If the member does not (and should not) do anything, you should consider removing the member definition to keep your code clean and manageable, and to eliminate confusion during code reviews.

See Also