The requested page is not available for the requested platform. You are viewing the content for Default platform.

Virtual member cannot be private

CodeRush Classic shows the Virtual member cannot be private code issue if a virtual member is marked as private.

Fix

Increase the member visibility.

Purpose

Highlights the virtual member declarations, which would cause the virtual or abstract members cannot be private compilation error.

Example

public class MyClass
{
    private virtual object ProcessData(object data)
    {
        if (Data != null)
            Data = data;
    }
    private object _Data;
    public object Data
    {
        get
        {
            return _Data;
        }
        set
        {
            ProcessData(value);
        }
    }
}

Fix:

public class MyClass
{
    protected virtual object ProcessData(object data)
    {
        if (Data != null)
            Data = data;
    }
    private object _Data;
    public object Data
    {
        get
        {
            return _Data;
        }
        set
        {
            ProcessData(value);
        }
    }
}