using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.IO;
namespace dessttrrr
{
class
Program
{
static void Main(string[] args)
{
string path
=
@
"C:\Users\admin1\Desktop\新建文件夹\newDll"
;
/
/
调用dll路径
Assembly assem
=
Assembly.LoadFile(path);
Type
[] tys;
try
{
tys
=
assem.GetTypes();
int
i
=
0
;
string []mystr
=
new string[
10000
];
int
j
=
0
;
foreach (
Type
ty
in
tys)
/
/
遍历查找类名
{
if
(ty.Name
=
=
"Program"
)
{
for
(; i <
10000
;
+
+
i)
{
ConstructorInfo magicConstructor
=
ty.GetConstructor(
Type
.EmptyTypes);
object
magicClassObject
=
magicConstructor.Invoke(new
object
[] { });
/
/
获取一个类实例
object
[] paramertors
=
new
object
[] { i };
/
/
需要传入的参数
MethodInfo[] methods
=
ty.GetMethods();
MethodInfo mi
=
ty.GetMethod(
"getStr"
);
/
/
获取方法
object
aa
=
mi.Invoke(magicClassObject, paramertors);
int
flag
=
String.Compare("", aa.ToString());
if
(flag !
=
0
)
{
int
flag2
=
aa.ToString()[
0
];
/
/
去除乱码
if
(flag2 <
255
)
{
mystr[j]
=
i.ToString()
+
": "
+
aa.ToString()
+
"\n"
;
+
+
j;
}
}
}
File
.WriteAllLines(
"str.txt"
, mystr, Encoding.Default);
}
}
}
catch (ReflectionTypeLoadException ex)
{
/
/
now look at ex.LoaderExceptions
-
this
is
an Exception[], so:
foreach (Exception inner
in
ex.LoaderExceptions)
{
/
/
write details of
"inner"
,
in
particular inner.Message
}
}
}
}
}