是否可以检索在当前appdomain中创建的所有静态对象?我正在尝试为现有的asp.net网站编写调试页面。它在基于单例对象的缓存中保存了大量信息。
感谢
答案 0 :(得分:0)
这是让你入门的东西:
IList<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies();
List<Type> allTypes = new List<Type>();
foreach (Assembly assembly in assemblies)
{
var types = from t in assembly.GetTypes()
where bootStrapperType.IsAssignableFrom(t)
&& !t.IsInterface && !t.IsAbstract
select t;
allTypes.AddRange(types);
}
foreach(Type type in allTypes)
{
var fieldsPublic = type.GetFields(BindingFlags.Public|BindingFlags.Static);
foreach(var field in fieldsPublic)
{
var nameAndValue = field.Name + " = " + field.GetValue(null);
// Do something
}
var fieldsPrivate = type.GetFields(BindingFlags.Private|BindingFlags.Static);
foreach(var field in fieldsPrivate)
{
var nameAndValue = field.Name + " = " + field.GetValue(null);
// Do something.
}
}
答案 1 :(得分:-1)