How to copy the summary of a method with Overload in C#

Asked

Viewed 52 times

1

I’m creating an application where in the classes I have a series of Overload's to optimise its performance and flexibility. Ex:

public class Calc 
{
    // método original com sumário

    /// <summary>
    /// soma "a" com "b"
    /// </summary>
    /// <returns></returns>
    public int soma(int a, int b) => a + b;

    // métodos complementares de conversão (overload) sem comentários

    public int soma(string a, int b) => soma(int.Parse(a), b);
    public int soma(string a, string b) => soma(int.Parse(a), int.Parse(b));
}

Is there any way, when I call one of the complementary methods, it show me the doc of the original method?

  • Why the doc of the original method, if they are different methods?

  • because for me they are not different methods, I may even have different input but by the business rule the result is the same

  • And who would you be?

  • Uai the Kra who created the question

1 answer

3


It has to be in the hand. If it was with override would be able to solve.

The most common case of Overload can avoid its use with arguments default, even is better, but in this case where changes the type does not give, because somehow in most cases changes the semantics and the description should be different.

In general copying and pasting the code into something of the same type is not usually difficult and as the contract should be very stable it should not have to change much. Anyway if you make a change without paying too much attention to the overloads you can make a mistake, so I don’t think it’s a serious tool failure. It’s that thing, comments are complicated, in a way they even violate the DRY.

  • got it... so there’s really no way... to do what you do... thank you anyway

Browser other questions tagged

You are not signed in. Login or sign up in order to post.