3

我有派生自它的 PersonBaseClass 和 EmployeeClass。现在我想在 BaseClass 中定义一个方法体作为注释,当我使用 Resharper 的“实现成员”(或手动实现它们)时,它也会将它放在方法体中。

(大致)这样的东西:

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 放在库中,并且它的实现通常每次看起来都一样。

4

1 回答 1

4

不完全是您要问的,但您可以使用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();
    }
}
于 2014-09-03T14:05:32.020 回答