我得到以下代码:
public class PluginShape : INotifyPropertyChanged
{
private string _Name;
public string Name
{
get { return _Name; }
set
{
_Name = value;
RaisePropertyChanged("Name");
}
}
#region Implement INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
public class SpeedGenerator : PluginShape
{
private int _SpeedValue;
public int SpeedValue
{
get { return _SpeedValue; }
set
{
_SpeedValue = value;
RaisePropertyChanged("SpeedValue");
}
}
public SpeedGenerator()
{
Name = "DefaultName";
}
}
然后我想过滤属性,以便我只获得 SpeedValue 属性。我认为以下代码可以,但它不起作用:
var props = obj.GetType().GetProperties();
var filteredProps = obj.GetType().GetProperties(BindingFlags.DeclaredOnly);
在“道具”中,我得到了 SpeedValue 和 Name 属性,但在“filteredProps”中,我什么也没得到……有什么帮助吗?