K
KC Eric
Hi all,
I have a dll file, it has a class, say:
class Temp,
this class has a function which has a delegate as a parameter,
say:
public void Test(GameOverHandler _overHandler)
the delegate type is declared in Namespace level,
say:
public delegate void GameOverHandler(string reason);
Now I have Another project, which needs to use that class and function in
That DLL,
I know that if everthing is in the same project, I can pass a function, say
public Abc(string reason), to Test easily by:
Test(new GameOverHandler(Abc));
How do I do this if that class and the delegate is defined in a dll file?
I have part of my code here,
foreach( string fileName in
Directory.GetFiles(Environment.CurrentDirectory.ToString(), "*.dll") )
{
try
{
Assembly a = Assembly.LoadFrom(fileName);
foreach( Type t in a.GetTypes() )
{
if (t.FullName.Equals("GameServerNS.GameOverHandler"))
{
// Here I want to instantiate the delegate, something like:
// GameOverHandler HANDLER = new GameOverHandler(abc);
// but I don't know how
}
if( t.IsClass && t.FullName.Equals("Game"))
{
object creator = a.CreateInstance(t.FullName);
try
{
MethodInfo StartServer = t.GetMethod("Test");
Object[] args1 = { //here I want to pass the Abc or the HANDLER,
but I also don't know how };
string status = (string) StartServer.Invoke(creator,args1);
catch (NullReferenceException exc)
{
}
}
}
}
I know the above code have other problems, but please leave them, I just use
the above code for my testing.
Thanks much!
KC Eric
--
-> ¹ª¨¬·F«l¡A¤Oª§¤W´å¡A¦h§Ö¦n¬Ù¦a«Ø³]²z·QFYP¥D¸q
-> °í¨M¿í±qÄPô¥|¶µªíz¡A¥þ±¸¨¹ê¤jÄPª÷Á`¸ô½u¡A¨«¦V¥|Óª«¥óªì©l¤Æ
-> ¯R¿Ë®Q¿Ë³£¤£¤Îª÷ÄPô¿Ë XDDD
-> To be energetic to strive for the best. To build our FYP idealism in a
flourishing, rapid, perfect and efficient manner.
-> To firmly adhere to Pango's Four Statements. To comprehensively implement
The Giant Pango's Great Scheme. To stride forward to the Initialization of
The Four Objects.
-> Parents are not as close as Pango. XDDD
I have a dll file, it has a class, say:
class Temp,
this class has a function which has a delegate as a parameter,
say:
public void Test(GameOverHandler _overHandler)
the delegate type is declared in Namespace level,
say:
public delegate void GameOverHandler(string reason);
Now I have Another project, which needs to use that class and function in
That DLL,
I know that if everthing is in the same project, I can pass a function, say
public Abc(string reason), to Test easily by:
Test(new GameOverHandler(Abc));
How do I do this if that class and the delegate is defined in a dll file?
I have part of my code here,
foreach( string fileName in
Directory.GetFiles(Environment.CurrentDirectory.ToString(), "*.dll") )
{
try
{
Assembly a = Assembly.LoadFrom(fileName);
foreach( Type t in a.GetTypes() )
{
if (t.FullName.Equals("GameServerNS.GameOverHandler"))
{
// Here I want to instantiate the delegate, something like:
// GameOverHandler HANDLER = new GameOverHandler(abc);
// but I don't know how
}
if( t.IsClass && t.FullName.Equals("Game"))
{
object creator = a.CreateInstance(t.FullName);
try
{
MethodInfo StartServer = t.GetMethod("Test");
Object[] args1 = { //here I want to pass the Abc or the HANDLER,
but I also don't know how };
string status = (string) StartServer.Invoke(creator,args1);
catch (NullReferenceException exc)
{
}
}
}
}
I know the above code have other problems, but please leave them, I just use
the above code for my testing.
Thanks much!
KC Eric
--
-> ¹ª¨¬·F«l¡A¤Oª§¤W´å¡A¦h§Ö¦n¬Ù¦a«Ø³]²z·QFYP¥D¸q
-> °í¨M¿í±qÄPô¥|¶µªíz¡A¥þ±¸¨¹ê¤jÄPª÷Á`¸ô½u¡A¨«¦V¥|Óª«¥óªì©l¤Æ
-> ¯R¿Ë®Q¿Ë³£¤£¤Îª÷ÄPô¿Ë XDDD
-> To be energetic to strive for the best. To build our FYP idealism in a
flourishing, rapid, perfect and efficient manner.
-> To firmly adhere to Pango's Four Statements. To comprehensively implement
The Giant Pango's Great Scheme. To stride forward to the Initialization of
The Four Objects.
-> Parents are not as close as Pango. XDDD