是否可以在抽象方法中继承注释';的主体来自基类
本文关键字:主体 基类 注释 抽象方法 继承 是否 | 更新日期: 2023-09-27 18:20:34
我有PersonBaseClass和从中派生的EmployeeClass。现在,我想将方法体定义为BaseClass中的注释,当我使用Resharper的"Implement Members"(或手动实现它们)时,它也会将其放在方法体中。
大致是这样的:
public abstract class PersonBaseClass : DependencyObject
{
//<methodComment>
// object connectionString;
// _configurations.TryGetValue("ConnectionString", out connectionString);
//</methodComment>
protected abstract void InstanceOnPersonChanged(object sender, EventArgs eventArgs);
}
当实施时,看起来是这样的:
public class EmployeeClass : PersonBaseClass
{
protected override void InstanceOnPersonChanged(object sender, EventArgs eventArgs)
{
// object connectionString;
// _configurations.TryGetValue("ConnectionString", out connectionString);
}
}
不知怎么的,这已经有可能了吗?无法将其用于GhostDoc。
编辑:这会很有用,因为我希望在库中拥有BaseClass,并且它的实现通常每次看起来都是一样的。
这不是您想要的,但您可以使用Ghostdoc将注释拉到继承的成员。请注意,它不会将注释添加到派生类方法的主体中,而是将其添加到注释部分中。
假设你有一个这样的类,带有注释嘿,这是一个很棒的方法:)
public abstract class PersonBaseClass
{
/// <summary>
/// Hey, this is great method :)
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="eventArgs">The <see cref="EventArgs" /> instance containing the event data.</param>
protected abstract void InstanceOnPersonChanged(object sender, EventArgs eventArgs);
}
然后添加派生类并覆盖成员,如
public class EmployeeClass : PersonBaseClass
{
protected override void InstanceOnPersonChanged(object sender, EventArgs eventArgs)
{
throw new NotImplementedException();
}
}
然后将光标放在派生类成员的主体内,并按ctrl+shift+d 在执行上述步骤之后,派生类将看起来像这样。public class EmployeeClass : PersonBaseClass
{
/// <summary>
/// Hey, this is great method :)
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="eventArgs">The <see cref="EventArgs" /> instance containing the event data.</param>
/// <exception cref="System.NotImplementedException"></exception>
protected override void InstanceOnPersonChanged(object sender, EventArgs eventArgs)
{
throw new NotImplementedException();
}
}