自动更新方法签名(例如摘要注释)

Automatically update method signature (for ex. summary comments)

我正在寻找一种方法来自动匹配接口、抽象 class 和派生 class 之间的方法签名。改一个评论的时候真的很痛苦,要手动更新3次,因为我要在界面更新,抽象class和派生class..有没有VS扩展或者可以帮助我自动做到这一点的东西?顺便说一句,我正在使用 ReSharper Ultimate。不确定它是否有这样的扩展名。

public interface IBotClient
{
    /// <summary>
    /// Gets account balance for an asset.
    /// </summary>
    /// <param name="asset">The asset.</param>
    /// <param name="ct">Cancellation token.</param>
    /// <returns>The account balance.</returns>
    /// <exception cref="T:ElonMuskBot.Core.Exceptions.CallFailedException">If the call fails.</exception>
    Task<Balance> GetBalanceAsync(string asset, CancellationToken ct = default);

    /// <summary>
    /// Gets account balances.
    /// </summary>
    /// <param name="ct">Cancellation token.</param>
    /// <returns>The account balances.</returns>
    /// <exception cref="T:ElonMuskBot.Core.Exceptions.CallFailedException">If the call fails.</exception>
    Task<IList<Balance>> GetBalancesAsync(CancellationToken ct = default);

    ...
}

public abstract class BotClientBase : IBotClient
{
    private readonly IBinanceClient _client;
    private readonly IBinanceSocketClient _socketClient;

    protected BotClientBase(IBinanceClient client, IBinanceSocketClient socketClient)
    {
        _client = client;
        _socketClient = socketClient;
    }

    /// <summary>
    /// Gets account balance for an asset.
    /// </summary>
    /// <param name="asset">The asset.</param>
    /// <param name="ct">Cancellation token.</param>
    /// <returns>The account balance.</returns>
    /// <exception cref="T:ElonMuskBot.Core.Exceptions.CallFailedException">If the call fails.</exception>
    public abstract Task<Balance> GetBalanceAsync(string asset, CancellationToken ct = default);

    /// <summary>
    /// Gets account balances.
    /// </summary>
    /// <param name="ct">Cancellation token.</param>
    /// <returns>The account balances.</returns>
    /// <exception cref="T:ElonMuskBot.Core.Exceptions.CallFailedException">If the call fails.</exception>
    public abstract Task<IList<Balance>> GetBalancesAsync(CancellationToken ct = default);

    ...
}

public class SpotBotClient : BotClientBase
{
    private readonly ILogger<SpotBotClient> _logger;
    private readonly IBinanceClient _client;
    private readonly IBinanceSocketClient _socketClient;

    public SpotBotClient(ILogger<SpotBotClient> logger, IBinanceClient client, IBinanceSocketClient socketClient) : base(client, socketClient)
    {
        _logger = logger ?? throw new ArgumentNullException(nameof(logger));
        _client = client;
        _socketClient = socketClient;
    }

    /// <summary>
    /// Gets account balance for an asset.
    /// </summary>
    /// <param name="asset">The asset.</param>
    /// <param name="ct">Cancellation token.</param>
    /// <returns>The account balance.</returns>
    /// <exception cref="T:ElonMuskBot.Core.Exceptions.CallFailedException">If the call fails.</exception>
    public override async Task<Balance> GetBalanceAsync(string asset, CancellationToken ct = default)
    {
        ...
    }

    /// <summary>
    /// Gets account balances.
    /// </summary>
    /// <param name="ct">Cancellation token.</param>
    /// <returns>The account balances.</returns>
    /// <exception cref="T:ElonMuskBot.Core.Exceptions.CallFailedException">If the call fails.</exception>
    public override async Task<IList<Balance>> GetBalancesAsync(CancellationToken ct = default)
    {
        ...
    }

    ...
}

我发现 ReSharper 内置了它。

Alt+Enter 覆盖方法,然后“从基础复制文档”。

C# 中的文档注释允许您使用 <inheritdoc> 标记,自动让派生类型重用层次结构中更高层的文档注释:

public interface IBotClient
{
    /// <summary>
    /// Gets account balance for an asset.
    /// </summary>
    /// <param name="asset">The asset.</param>
    /// <param name="ct">Cancellation token.</param>
    /// <returns>The account balance.</returns>
    /// <exception cref="T:ElonMuskBot.Core.Exceptions.CallFailedException">If the call fails.</exception>
    Task<Balance> GetBalanceAsync(string asset, CancellationToken ct = default);

    /// <summary>
    /// Gets account balances.
    /// </summary>
    /// <param name="ct">Cancellation token.</param>
    /// <returns>The account balances.</returns>
    /// <exception cref="T:ElonMuskBot.Core.Exceptions.CallFailedException">If the call fails.</exception>
    Task<IList<Balance>> GetBalancesAsync(CancellationToken ct = default);

    ...
}

///<inheritdoc cref="IBotClient"/>
public abstract class BotClientBase : IBotClient
{
    
}

///<inheritdoc/>
public class SpotBotClient : BotClientBase
{
    
}