该事件只能出现在+ =或 - +的左侧

时间:2018-04-05 17:37:57

标签: c# visual-studio-2017

我有一个在基类中定义的事件:

public event EventHandler<HighestSeverityLevelChangedEventArgs> HighestSeverityLevelChanged;

事件参数定义为:

   public sealed class HighestSeverityLevelChangedEventArgs : EventArgs
{
    /// <summary>
    /// Hold the highest severity level.
    /// </summary>
    public int HighestSeverityLevel { get; set; }

    /// <summary>
    /// Holds the previously high severity level.
    /// </summary>
    public int PreviousHighestSeverityLevel { get; set; }

    /// <summary>
    /// Initializes a new instance of the <see cref="HighestSeverityLevelChangedEventArgs" /> class.
    /// </summary>
    /// <param name="highestSeverityLevel">Input current high severity level</param>
    /// <param name="previousHighestSeverityLevel"></param>
    public HighestSeverityLevelChangedEventArgs(int highestSeverityLevel, int previousHighestSeverityLevel)
    {
        #region Preconditions

        if (highestSeverityLevel < 0)
        {
            throw new InvalidOperationException(nameof(highestSeverityLevel));
        }

        if (previousHighestSeverityLevel < 0)
        {
            throw new InvalidOperationException(nameof(previousHighestSeverityLevel));
        }

        #endregion

        HighestSeverityLevel = highestSeverityLevel;
        PreviousHighestSeverityLevel = previousHighestSeverityLevel;
    }
}

现在在子类中,我必须引发事件,所以我使用以下行:

HighestSeverityLevelChanged?.Invoke(this, new HighestSeverityLevelChangedEventArgs(m_highestLevel, previousHighestLevel));

但这不是编译,它告诉我: 在基类中使用时,事件只能出现在+ =或 - + excep的左侧。

我在继承的类中有这个代码,所以这里的语法不同,因为我试图在继承的类中提高它。我做错了什么?

0 个答案:

没有答案