从 DLL/程序集中过滤 DependencyObject 和 DependencyProperties?
我得到了以下代码来生成 DLL:
public class QtObject : DependencyObject
{
public int speedSimu
{
get { return (int)GetValue(speedSimuProperty); }
set { SetValue(speedSimuProperty, value); }
}
public static readonly DependencyProperty speedSimuProperty =
DependencyProperty.Register("speedSimu", typeof(int), typeof(QtObject), new PropertyMetadata(0));
public int rpmSimu
{
get { return (int)GetValue(rpmSimuProperty); }
set { SetValue(rpmSimuProperty, value); }
}
public static readonly DependencyProperty rpmSimuProperty =
DependencyProperty.Register("rpmSimu", typeof(int), typeof(QtObject), new PropertyMetadata(0));
public int nbSimu;
}
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 time"));
public bool isActive
{
get { return (bool)GetValue(isActiveProperty); }
set { SetValue(isActiveProperty, value); }
}
public static readonly DependencyProperty isActiveProperty =
DependencyProperty.Register("isActive", typeof(bool), typeof(Timer), new PropertyMetadata(true));
}
public class AnotherClass
{
//blaaa
}
我现在只想获取 DependencyObject/Properties。 (即没有属性“nbSimu”并且没有对象“AnotherClass”)
这是我的代码:
var library = Assembly.LoadFrom(libraryPath);
IEnumerable<Type> types = library.GetTypes();
var libs = types.Where(t => true);
foreach (Type type in libs)
{
foreach (PropertyInfo property in type.GetProperties())
{
//TODO
}
}
在我尝试的第三行:
var libs = types.Where(t => t.BaseType == typeof(DependencyObject));
它没有说任何错误,但没有过滤任何内容......
以及关于过滤 DependencyProperties ,我只是不知道该怎么做...
提前感谢您对这两个问题的任何帮助。
I got the following code to generate a DLL :
public class QtObject : DependencyObject
{
public int speedSimu
{
get { return (int)GetValue(speedSimuProperty); }
set { SetValue(speedSimuProperty, value); }
}
public static readonly DependencyProperty speedSimuProperty =
DependencyProperty.Register("speedSimu", typeof(int), typeof(QtObject), new PropertyMetadata(0));
public int rpmSimu
{
get { return (int)GetValue(rpmSimuProperty); }
set { SetValue(rpmSimuProperty, value); }
}
public static readonly DependencyProperty rpmSimuProperty =
DependencyProperty.Register("rpmSimu", typeof(int), typeof(QtObject), new PropertyMetadata(0));
public int nbSimu;
}
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 time"));
public bool isActive
{
get { return (bool)GetValue(isActiveProperty); }
set { SetValue(isActiveProperty, value); }
}
public static readonly DependencyProperty isActiveProperty =
DependencyProperty.Register("isActive", typeof(bool), typeof(Timer), new PropertyMetadata(true));
}
public class AnotherClass
{
//blaaa
}
I now would like to ONLY get DependencyObject/Properties. (ie without property "nbSimu" and without object "AnotherClass")
Here is the code I have :
var library = Assembly.LoadFrom(libraryPath);
IEnumerable<Type> types = library.GetTypes();
var libs = types.Where(t => true);
foreach (Type type in libs)
{
foreach (PropertyInfo property in type.GetProperties())
{
//TODO
}
}
On the 3rd line I tried :
var libs = types.Where(t => t.BaseType == typeof(DependencyObject));
It doesn't say any error, but doesn't filter anything...
And about filtering the DependencyProperties, I just got no idead about how to do it...
Thanks in advance for any help on it, on both problems.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
var libs = types.Where(t => t.IsSubclassOf(typeof(DependencyObject))); 应该可以工作。
var libs = types.Where(t => t.IsSubclassOf(typeof(DependencyObject)));
should work.它适用于我的电脑。
第二个问题怎么样..您应该遵守属性/字段的命名约定
It works on my comp.
What about second problem.. you should keep to naming convention of your properties/fields