Protected member in sealed type will be private
CodeRush Classic shows the Protected member in sealed type will be private code issue if a protected member is declared within a sealed class.
#Fix
Make the member private.
#Purpose
Highlights the sealed class member declarations, which would cause the ‘Member name’: new protected member declared in a sealed class compilation warning.
#Example
public sealed class MyClass
{
private string _Text;
public string Text
{
get { return _Text; }
set
{
_Text = value;
ProcessText(_Text);
}
}
protected void │ProcessText(string text)
{
Console.WriteLine(text);
}
}
Fix:
public sealed class MyClass
{
private string _Text;
public string Text
{
get { return _Text; }
set
{
_Text = value;
ProcessText(_Text);
}
}
private void ProcessText(string text)
{
Console.WriteLine(text);
}
}