Operator must declare a body
CodeRush Classic shows the Operator must declare a body code issue if an operator does not declare a body.
#Fix
Declare the operator body.
#Purpose
Highlights the operator declarations, which would cause the Member must declare a body because it is not marked abstract, extern, or partial compilation error.
#Example
public class MyData
{
public MyData(string name, List<string> data)
{
Name = name;
Data = data;
}
public string Name { get; set; }
public List<string> Data { get; set; }
public static MyData operator │+(MyData d1, MyData d2);
}
Fix:
public class MyData
{
public MyData(string name, List<string> data)
{
Name = name;
Data = data;
}
public string Name { get; set; }
public List<string> Data { get; set; }
public static MyData operator +(MyData d1, MyData d2)
{
string newName = String.Format("{0}&{1}", d1.Name, d2.Name);
List<string> newData = d1.Data;
newData.AddRange(d2.Data);
return new MyData(newName, newData);
}
}