0

How to define generic class for mapping muti-class? I asked the question before,but i want like this

 public class BaseRepositoryService<T1,T2,T3...Tn> where T:class
{
    maplestory2Context mc = new maplestory2Context();


    public T AddEntity(params object [] args)
    {
        for (int i = 0; i < args.Length; i++)
        {
            object obj = args[i];


        }

    }


}

but i am not sure the how many params I would use. thanks.

note:i changed my code below,but it is not convenience.

public class BaseRepositoryService<T> where T:class
{
    maplestory2Context mc = new maplestory2Context();


    public T AddEntity(T entity,int size)
    {
        if (size == 2)
        { 

        }

        return null;
    }


}


public class BaseRepositoryService<T,T2> 
    where T : class
    where T2:class
{
    maplestory2Context mc = new maplestory2Context();


    public T AddEntity(T entity, int size)
    {
        if (size == 2)
        {

        }

        return null;
    }


}
Community
  • 1
  • 1
Youku KMSFan
  • 67
  • 2
  • 12

1 Answers1

1

Answer to this question is you can't.

You need to define n no of classes for that even Microsoft has defined Func delegates 15 or 16 times. You can refer to msdn documentation for confirmation.

If you don't want write those classes manually you may opt for t4 templates as code generator.

Jenish Rabadiya
  • 6,708
  • 6
  • 33
  • 62