Search code examples
c#overloadingconflictmethod-signature

How Do I Handle Conflicts in Overloaded Method Signatures?


I have a feeling this question is a can of worms but I am going to ask anyway... :)

I have a method:

private MembershipUser GetUserFromReader(SqlDataReader reader)

And I want overload this method with a different return type:

private User GetUserFromReader(SqlDataReader reader)

But the compiler complains that the two methods have the same signature.

So, what is the best way to do this? I would prefer to not add an unnecessary parameter just to change the method signature.

I have played with the idea of doing something like:

private User GetUserFromReader(T reader)

But haven't really explored this in full yet. It seems like I'll need to make a bunch of changes with how I use my reader object.

Any ideas? What is the best practice when you have two overloaded methods of the same signature?

Thanks for helping out...


Solution

  • Why overload it? Why not just let the method say what it does, like so:

    private MembershipUser GetMembershipUserFromReader(SqlDataReader reader)
    private User GetUserFromReader(SqlDataReader reader)