我有从中派生的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放在一个库中,并且它的实现通常每次都相同。
不完全是您要问的内容,但是您可以使用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();
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句