1

Suppose I have 2 methods similar to:

public List<object> Do<T>(Stream stream)
{
    ...  does cool things
}

public List<object> Do(Type type, Stream stream)
{
    T = type // <- what should this be
    return Do<T>(Stream);
}

What is the code that allows this to operate as expected?

I imagine this question has to duplicate something on here but I couldn't find it with my google-fu.

Chris Marisic
  • 32,487
  • 24
  • 164
  • 258

1 Answers1

8

It's pretty easy if you do it the other way around:

public List<object> Do<T>(Stream stream)
{
    var type = typeof(T);
    Do(type, stream);
}

Then the other method would contain the non-duplicated logic.

mellamokb
  • 56,094
  • 12
  • 110
  • 136