我的要求如下,这可能吗?如果是,有人可以指点我的任何资源吗?
答案 0 :(得分:2)
试试这个:
foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
if (asm.GetName().Name.EndsWith("static"))
{
foreach(Type type in asm.GetTypes())
{
if (type.Name.EndsWith("cache"))
{
MethodInfo method = type.GetMethod("invalidate", BindingFlags.Static | BindingFlags.Public, null, Type.EmptyTypes, null);
if (method != null)
method.Invoke(null, null);
}
}
}
}
或者......如果您更喜欢LINQ:
foreach(MethodInfo method in
AppDomain.CurrentDomain
.GetAssemblies().Where(asm => asm.GetName().Name.EndsWith("static"))
.SelectMany(asm => asm.GetTypes().Where(type => type.Name.EndsWith("cache"))
.Select(type => type.GetMethod("invalidate", BindingFlags.Static | BindingFlags.Public, null, Type.EmptyTypes, null)).Where(method => method != null)))
method.Invoke(null, null);