Created
May 16, 2025 05:50
-
-
Save etar125/6a00773f63258f67e6e9af6bc23d9336 to your computer and use it in GitHub Desktop.
Вызов функции из сторонней либы в C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Взято из кода LSWWA */ | |
/* Прототип функции из библиотеки | |
public static void Do(string func, string arg, object[] other); */ | |
/* Извлечение функции из библиотеки */ | |
string[] sl = Globl.SplitByFirst(arg, ' '); | |
string dll = sl[0]; | |
string name = sl[1]; | |
if (File.Exists(dll + ".dll")) | |
{ | |
Assembly a = Assembly.Load(dll); // Загружаем библиотеку | |
Object o = a.CreateInstance("Program"); // Получаем классы | |
Type t = a.GetType(name + ".Program"); // Получаем класс | |
MethodInfo mi = t.GetMethod("Do"); // Получаем метод | |
libs.Add(name, new object[] { o, mi }); | |
} | |
else | |
throw new Exception("Not found file " + dll + ".dll"); | |
/* Вызов с аргументами */ | |
object[] objs = libs[ll[0]]; | |
object[] args = | |
{ | |
ll[1], | |
arg, | |
new object[] | |
{ | |
Program.fil, | |
Program.cod, | |
Program.vars, | |
Program.arrs, | |
indx, | |
Globl.Version + "." + Globl.SubVersion + "." + Globl.Build | |
} | |
}; | |
Object o = objs[0]; | |
MethodInfo mi = (MethodInfo)objs[1]; | |
mi.Invoke(o, args); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment