Interface expected
- 2 minutes to read
CodeRush Classic shows the Interface expected code issue if a structure inherits a type, but not an interface.
#Fix
Make sure that the current structure inherits only interfaces.
#Purpose
Highlights the structure declaration statements, which would cause the Type ‘Type name’ in interface list is not an interface compilation error.
#Example
public class MyStructBase
{
public virtual string Name { get; protected set; }
public virtual int Index { get; protected set; }
public virtual object Data { get; set; }
}
public struct MyStruct: │MyStructBase
{
public MyStruct(string name, int index, object data)
{
Index = index;
Name = name;
Data = data;
}
public override string Name { get; private set; }
public override int Index { get; private set; }
public override object Data { get; set; }
}
Fix:
public interface IMyStruct
{
string Name { get; private set; }
int Index { get; private set; }
object Data { get; set; }
}
public struct MyStruct: IMyStruct
{
public MyStruct(string name, int index, object data)
{
Index = index;
Name = name;
Data = data;
}
public string Name { get; private set; }
public int Index { get; private set; }
public object Data { get; set; }
}