Is it possible to inherit comments in an abstract method's body from a BaseClass?

2.2k Views Asked by At

I have the PersonBaseClass and the EmployeeClass that derives from it. Now I'd like to define a method body as a comment in the BaseClass that when I use Resharper's "Implement Members" (or manually implement them) it also puts it in the method body.

Something (roughly) like that:

public abstract class PersonBaseClass : DependencyObject
{
   //<methodComment>
   // object connectionString;
   // _configurations.TryGetValue("ConnectionString", out connectionString);
   //</methodComment>
   protected abstract void InstanceOnPersonChanged(object sender, EventArgs eventArgs);
}

That when implemented will look like that:

public class EmployeeClass : PersonBaseClass
{
    protected override void InstanceOnPersonChanged(object sender, EventArgs eventArgs)
    {
        // object connectionString;
        // _configurations.TryGetValue("ConnectionString", out connectionString);
    }
}

Is that already possible somehow ? Couldn't get this to work with GhostDoc.

Edit: It would be useful as I want to have the BaseClass in a library and the implementation of it usually looks the same every time.

1

There are 1 best solutions below

3
On BEST ANSWER

Not exactly what you're asking, but you can pull the comments using Ghostdoc to the inherited members. Note that it will not add the comments to derived class method's body but it will add it in its comment section.

Assume you have a class like this, with comment Hey, this is great method :)

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);
}

Then you add derived class and override the member like this

public class EmployeeClass : PersonBaseClass
{
    protected override void InstanceOnPersonChanged(object sender, EventArgs eventArgs)
    {
        throw new NotImplementedException();
    }
}

Then place the cursor inside the derived class member's body and press ctrl + shift + d. It will pull the comments from base class.

And your derived class will look something like this after performing above step.

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();
    }
}