Click here to Skip to main content
16,015,827 members
Home / Discussions / C#
   

C#

 
GeneralRe: Vb to C# Pin
Guffa31-Jan-08 21:41
Guffa31-Jan-08 21:41 
GeneralRe: Vb to C# Pin
Guffa31-Jan-08 21:56
Guffa31-Jan-08 21:56 
GeneralRe: Vb to C# Pin
Vikram A Punathambekar1-Feb-08 1:47
Vikram A Punathambekar1-Feb-08 1:47 
GeneralRe: Vb to C# Pin
Pete O'Hanlon1-Feb-08 3:39
mvePete O'Hanlon1-Feb-08 3:39 
GeneralRe: Vb to C# Pin
Guffa1-Feb-08 5:11
Guffa1-Feb-08 5:11 
JokeRe: Vb to C# Pin
DavidNohejl1-Feb-08 6:17
DavidNohejl1-Feb-08 6:17 
GeneralRe: Vb to C# Pin
Guffa1-Feb-08 5:16
Guffa1-Feb-08 5:16 
Questionhow to call DLL function in generic method? Pin
vicky45731-Jan-08 9:32
vicky45731-Jan-08 9:32 
Hi,
I am trying to get my first generic method work. Here is what I want to do:
Based on diffent type of users, we need to use different DLL. The DLL is COM object wrapper, which expose a function that can be called. The original code looks like the following:

using System.Runtime.InteropServices;
using AsynchWrapper1;
using AsynchWrapper2;
using AsynchWrapper3;
....
namespace MyNameSpace
{
public class Unility
{
public static void CallAsynchWrapper(int clientType, int clientId)
{
if (clientType ==0)
{
clsAsynchWrapper1 asynchWrapper = new clsAsynchWrapper1();

asynchWrapper.XYZ(clientId);

Marshal.ReleaseComObject(asynchWrapper);

asynchWrapper = null;

}
else if (clientType ==1)
{
clsAsynchWrapper2 asynchWrapper = new clsAsynchWrapper2();

asynchWrapper.XYZ(clientId);

Marshal.ReleaseComObject(asynchWrapper);

asynchWrapper = null;

}

else

{

clsAsynchWrapper3 asynchWrapper = new clsAsynchWrapper3();

asynchWrapper.XYZ(clientId);

Marshal.ReleaseComObject(asynchWrapper);

asynchWrapper = null;

}

}

}

Where XYZ is the function that all 3 DLLs expose.



I want to make a generic method by modifying the CallAsynchWrapper function doing the following:

public static void CallAsynchWrapper(int clientType, int clientId)
{
if (clientType ==0)
{
clsAsynchWrapper1 asynchWrapper = new clsAsynchWrapper1();

genericCallAsynchWrapper<clsasynchwrapper1>(asynchWrapper, clientId);

}
else if (clientType ==1)
{
clsAsynchWrapper2 asynchWrapper = new clsAsynchWrapper2();

genericCallAsynchWrapper<clsasynchwrapper2>(asynchWrapper, clientId);

}

else

{

clsAsynchWrapper3 asynchWrapper = new clsAsynchWrapper3();

genericCallAsynchWrapper<clsasynchwrapper3>(asynchWrapper, clientId);

}

}



and add a generic method:

static void genericCallAsynchWrapper<t>(T asynchWrapper, int clientId)

{

asynchWrapper.XYZ(clientId);

Marshal.ReleaseComObject(asynchWrapper);

asynchWrapper = default(T);

}



When I compile it, I got error message” T doesn’t have a definition of XYZ.”

My first question is: Is that possible to make a generic method for what I am trying to do?

If that’s possible, how can I make compiler knows that T does have XYZ?

Does anybody know the answer?

Thanks in advance for any help!
AnswerRe: how to call DLL function in generic method? Pin
S. Senthil Kumar1-Feb-08 6:02
S. Senthil Kumar1-Feb-08 6:02 
GeneralRe: how to call DLL function in generic method? Pin
vicky4571-Feb-08 6:58
vicky4571-Feb-08 6:58 
QuestionHow to assign DataView to Datatable Pin
ss.mmm31-Jan-08 9:27
ss.mmm31-Jan-08 9:27 
AnswerRe: How to assign DataView to Datatable Pin
J$31-Jan-08 9:38
J$31-Jan-08 9:38 
GeneralComboBox TextChanged Event firing unexpectedly [modified] Pin
DaveyM6931-Jan-08 8:29
professionalDaveyM6931-Jan-08 8:29 
GeneralThreading help Pin
daphne7531-Jan-08 8:21
daphne7531-Jan-08 8:21 
GeneralRe: Threading help Pin
Luc Pattyn31-Jan-08 11:03
sitebuilderLuc Pattyn31-Jan-08 11:03 
GeneralRe: Threading help Pin
daphne751-Feb-08 9:19
daphne751-Feb-08 9:19 
GeneralLogging Shutdown event in Windows Service Pin
abupsman31-Jan-08 7:46
abupsman31-Jan-08 7:46 
GeneralRe: Logging Shutdown event in Windows Service Pin
CKnig31-Jan-08 18:56
CKnig31-Jan-08 18:56 
QuestionHow to instantiate an object with a generic parameter? Pin
michal.kreslik31-Jan-08 7:31
michal.kreslik31-Jan-08 7:31 
AnswerRe: How to instantiate an object with a generic parameter? Pin
Giorgi Dalakishvili31-Jan-08 8:18
mentorGiorgi Dalakishvili31-Jan-08 8:18 
AnswerRe: How to instantiate an object with a generic parameter? Pin
Ennis Ray Lynch, Jr.31-Jan-08 9:00
Ennis Ray Lynch, Jr.31-Jan-08 9:00 
AnswerRe: How to instantiate an object with a generic parameter? Pin
Le centriste31-Jan-08 10:05
Le centriste31-Jan-08 10:05 
GeneralRe: How to instantiate an object with a generic parameter? Pin
michal.kreslik31-Jan-08 10:26
michal.kreslik31-Jan-08 10:26 
GeneralRe: How to instantiate an object with a generic parameter? Pin
Le centriste31-Jan-08 12:59
Le centriste31-Jan-08 12:59 
GeneralRe: How to instantiate an object with a generic parameter? Pin
michal.kreslik31-Jan-08 13:17
michal.kreslik31-Jan-08 13:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.