| View previous topic :: View next topic |
| Author |
Message |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
Posted: Thu Sep 16, 2010 10:39 am Post subject: C# reflection need help. |
|
|
Hello.
I'm trying to figure out how to design a dll to trigger this code. My book didn't cover it so I don't know what to do.
| Code: | foreach (string f in Directory.GetFiles(System.Environment.CurrentDirectory, "addon-*.dll"))
{
Assembly asm = Assembly.LoadFile(f);
object[] descs = asm.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);
AssemblyDescriptionAttribute desc = (AssemblyDescriptionAttribute)descs[0];
Console.WriteLine(desc.Description);
foreach (Type t in asm.GetTypes())
{
if (t.Name.EndsWith("Greeting"))
{
MethodInfo greet = t.GetMethod("Greet");
greet.Invoke(null, null);
break;
}
}
} |
Hmm.. So I need a class named greeting with a method called Greet? and the dll can be named addon-andsomerandomname.dll
_________________
Intel over amd yes. |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Thu Sep 16, 2010 1:25 pm Post subject: |
|
|
You may need to use Assembly.LoadFrom instead of LoadFile.
Use the LoadFile method to load and examine assemblies that have the same identity, but are located in different paths. LoadFile does not load files into the LoadFrom context, and does not resolve dependencies using the load path, as the LoadFrom method does. LoadFile is useful in this limited scenario because LoadFrom cannot be used to load assemblies that have the same identities but different paths; it will load only the first such assembly.
_________________
- Retired. |
|
| Back to top |
|
 |
NINTENDO Grandmaster Cheater Supreme
Reputation: 0
Joined: 02 Nov 2007 Posts: 1371
|
|
| Back to top |
|
 |
Csimbi I post too much
Reputation: 98
Joined: 14 Jul 2007 Posts: 3399
|
Posted: Thu Sep 16, 2010 5:44 pm Post subject: Re: sorry. i not clear |
|
|
| NINTENDO wrote: | | My questions was (ye i forgot to write them) |
A classic, LOL
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Fri Sep 17, 2010 12:30 am Post subject: |
|
|
| You should define an abstract base class that these plugins inherit from, and then check for the existence of this base class. It's quite a bit more stable when you do it this way (and has the advantage of providing a limited 'API' of sorts).
|
|
| Back to top |
|
 |
|