The equals code snippets provided by Visual Studio is expanded as follows:
// Override object. equals
Public override bool equals (Object OBJ)
{
//
// See the full list of guidelines
// Http://go.microsoft.com/fwlink? Linkid = 85237
// And also the guidance for operator =
// Http://go.microsoft.com/fwlink? Linkid = 85238
//
If (OBJ = NULL | GetType ()! = Obj. GetType ())
{
Return false;
}
// Todo: Write Your Implementation of equals () here
Throw new notimplementedexception ();
Return base. Equals (OBJ );
}
// Override object. gethashcode
Public override int gethashcode ()
{
// Todo: Write Your Implementation of gethashcode () here
Throw new notimplementedexception ();
Return base. gethashcode ();
}
I think there are the following Disadvantages:
- Use GetType ()! = Obj. GetType () to determine the type. It is clear that the derived type is not considered.
- There is no strongly typed equals method execution.
- Contains additional comments.
Therefore, I wrote an enhanced code snippets, named sex. Overcome these shortcomings.
When you use sex in a type:
The Expo was launched as follows:
Class
{
Public override bool equals (Object OBJ)
{
VaR TMP = OBJ as;
If (TMP = NULL)
{
Return false;
}
Return equals (TMP );
}
Public bool equals (a obj)
{
}
Public override int gethashcode ()
{
}
}
It automatically contains the correct, strong type equals method execution! The gethashcode method is also available.
File Download
Download Page
Note: the link is the Microsoft SkyDrive page. When downloading, use a browser to download it directly. Some download tools may not be available for downloading.
File Type:. snippet File