0

I need to make a general class for transform Tuple data, to Data Set. Is possible to call "unknown data method's" with different return type. For example <Tuple<List<string,int>>, <Tuple<List<int,int>> and put it in like generic type?

I have a generic Class

static class Helper<T>
{
    public static DataSet Transform(T data)
    {
        ...transform logic
        return new DataSet();
    }
}

And another class, which call different methods, which return different types.

For example, I call a method which returns this type: Tuple<List<Tuple<long, string, string>>, List<Tuple<long, string, string>>> and I try to call generic class method Transform and insert specific date type, which I get from method result by GetType(). But I have a problem with it.

For Example - this work, I set string like generic type and string content.

Helper<string>.Transform("test");

But if I want to use "unknown" type, I don't know, how I put it like date type.

var data = Data.GetData();
var type = data.GetType();
//this doesn't work
Helper<type>.Transform(data);

I hope so my question is clear.

Thanks for your help.

Sibiraj
  • 4,486
  • 7
  • 33
  • 57
tomas
  • 153
  • 2
  • 13
  • In the past I have used a non generic class and a method with a type parameter e.g. ```public static DataSet Transform(Type type, Object data)``` Also look up ```Activator.CreateInstance``` if you need to create an instance of a partiicular type. – kpollock Jul 24 '17 at 12:14
  • Oh thanks, Type and Object like input works fine, i want to try some generic, but if it doesn't work, i will use it. – tomas Jul 24 '17 at 12:19

0 Answers0