Based on your second method if you want to call that using c# Func , here is the code below.
public class Stackoverflow<T>
{
public static Func<string,string,IDbDataParameter[],T> CallingFunc;
public static T GetField(string tableName, string fieldName, params IDbDataParameter[] parameters)
{
//Code
return default(T);
}
}
public class MainProgram
{
static void Main(string[] args)
{
Stackoverflow<int>.CallingFunc = Stackoverflow<int>.GetField;
Stackoverflow<int>.CallingFunc("SampleTableName", "SampleField", new[]{
new SqlParameter{DbType = DbType.Int32,Size = sizeof(Int32),ParameterName = "Id",Direction = ParameterDirection.Input},
new SqlParameter{DbType = DbType.String,Size = 100,ParameterName = "name",Direction = ParameterDirection.Output}
});
}
}
Main method can't be call under generic class, so it's reside in other class. This workaround also can be possible using generic delegates like below
public class Stackoverflow<T>
{
public delegate T CallingDelegate(string tableName, string fieldName, params IDbDataParameter[] parameters);
public static T GetField(string tableName, string fieldName, params IDbDataParameter[] parameters)
{
//Code
return default(T);
}
}
public class MainProgram
{
static void Main(string[] args)
{
Stackoverflow<int>.CallingDelegate del = Stackoverflow<int>.GetField;
del("SampleTableName", "SampleField", new[]{
new SqlParameter{DbType = DbType.Int32,Size = sizeof(Int32),ParameterName = "Id",Direction = ParameterDirection.Input},
new SqlParameter{DbType = DbType.String,Size = 100,ParameterName = "name",Direction = ParameterDirection.Output}
});
}
}