DLL的依赖对象/属性

这是我的代码:

public class MyObject : DependencyObject { public int speedSimu { get { return (int)GetValue(speedSimuProperty); } set { SetValue(speedSimuProperty, value); } } public static readonly DependencyProperty speedSimuProperty = DependencyProperty.Register("speedSimu", typeof(int), typeof(MyObject), new PropertyMetadata(0)); public int Value { get; set; } } public class Timer : DependencyObject { public string description { get { return (string)GetValue(descriptionProperty); } set { SetValue(descriptionProperty, value); } } public static readonly DependencyProperty descriptionProperty = DependencyProperty.Register("description", typeof(string), typeof(Timer), new PropertyMetadata("This is a timer")); } public class AnotherClass { } public class Test { MyObject q1 = new MyObject(); MyObject q2 = new MyObject(); MyObject q3 = new MyObject(); MyObject q4 = new MyObject(); Timer t1 = new Timer(); Timer t2 = new Timer(); Timer t3 = new Timer(); AnotherClass a1 = new AnotherClass(); AnotherClass a2 = new AnotherClass(); AnotherClass a3 = new AnotherClass(); } 

我从这段代码生成一个DLL,这就是我想做的事情: – 只获取实例(==忽略所有类,但“test”):OK – filter DependencyObjects:OK – filter DependencyProperties:not OK – 访问信息,这样我就可以了得到我想要的东西(我不想要更多):

q1 int speedSimu:0 q2 int speedSimu:0 q3 int speedSimu:0 q4 int speedSimu:0

t1字符串描述:“这是一个计时器”t2字符串描述:“这是一个计时器”

(注意比!dependecyProperties被忽略)

我现在的守则是:

 var library = Assembly.LoadFrom(libraryPath); IEnumerable types = library.GetTypes(); foreach (Type type in types) { var lib = Activator.CreateInstance(type); Type myType = lib.GetType(); //This filters my Class Test. Not elegant but not my main problem at the moment. if (myType.BaseType.ToString() == "System.Object") { FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Instance); foreach (FieldInfo field in fields) { var fieldtype = field.FieldType; if (typeof(DependencyObject).IsAssignableFrom(fieldtype)) { //Here I am ! } } } } 

问题是,在这一点上,我认为我接近结束,但在我看来,在“FieldInfos”中,关于MyObject和Timer的信息都丢失了(我的意思是属性/字段,它们的值……)但是我不知道如何以不同的方式做到这一点……我真的被封锁了,不知道下一步该做什么……