Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Copy <summary> from other class

Tags:

c#

xml

I wanted to declare a new enum/class , but with the exact same <summary> from existing class (for programming purpose) , in small scale i can just type the summary manually , but in large scale it takes just too much time copying and pasting , especially with really long <summary> . How do i do it ?

For example :

/// <summary>
/// Animal
/// </summary>
public enum AnimalListOne {
cat,wolves,fox
}

/// <summary>
/// ..... how do i copy the summary of AnimalListOne ?
/// </summary>
public enum AnimalListTwo {
horse , horseagain , andhorseagain , horsearethebest
}
like image 345
user6668201 Avatar asked Feb 16 '26 23:02

user6668201


2 Answers

I just tried it out, so I know it works. The <inheritdoc src="YourClass"/> works just perfect for your needs.

like image 139
Jose Manuel Lepe Avatar answered Feb 19 '26 11:02

Jose Manuel Lepe


Unfortunately there isn't a built-in way that I can see in VS2019, or even an easy set of keystrokes, but if you add the Visual Commander Extension, you can add a Command to help you. Unfortunately Visual Commander is somewhat buggy, and won't record the macro for you, but you can add it:

using EnvDTE;
using EnvDTE80;

public class M : VisualCommanderExt.ICommand
{
    public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
    {
        DTE.ExecuteCommand("Edit.ExpandSelection");
        DTE.ExecuteCommand("Edit.ExpandSelection");
        DTE.ExecuteCommand("Edit.ExpandSelection");
        DTE.ExecuteCommand("Edit.ExpandSelection");
        DTE.ExecuteCommand("Edit.ExpandSelection");
        DTE.ExecuteCommand("Edit.ExpandSelection");
        DTE.ExecuteCommand("Edit.ExpandSelection");
        DTE.ExecuteCommand("Edit.ExpandSelection");
        DTE.ExecuteCommand("Edit.ExpandSelection");
        DTE.ExecuteCommand("Edit.ExpandSelection");
        DTE.ExecuteCommand("Edit.SwapAnchor");
        DTE.ExecuteCommand("Edit.LineStartExtend");
        DTE.ExecuteCommand("Edit.LineStartExtend");
        DTE.ExecuteCommand("Edit.Copy");
        DTE.ExecuteCommand("Edit.NextMethod");
        DTE.ExecuteCommand("Edit.NextMethod");
        DTE.ExecuteCommand("Edit.LineStart");
    }
}

Put the cursor anywhere in a method comment block, and run the macro. It will copy the comment block to the clipboard and move the cursor to the beginning of the following method. Then you can either paste, or click to put the cursor at the beginning of another method and paste.

like image 41
NetMage Avatar answered Feb 19 '26 13:02

NetMage