C#,BindingSource和DataSource
例如:C#,BindingSource和DataSource,c#,reflection,bindingsource,C#,Reflection,Bindingsource,例如: public class MyProperty { //something.. } public class MyClass { private MyProperty[] myProperty = null; public MyProperty[] myProperty { get { //execute some code return myPrope
public class MyProperty
{
//something..
}
public class MyClass
{
private MyProperty[] myProperty = null;
public MyProperty[] myProperty
{
get
{
//execute some code
return myProperty;
}
set
{
myProperty = value;
}
}
}
MyClass testMyClass = new MyClass();
myBindingSource.DataSource = testMyClass.MyProperty;
是否有一种方法,可以使用反射(或从BindingSource继承)获取对MyClass.MyProperty实例的引用,而不是只包含MyProperty[]的对象
BindingSource.DataSource只返回可以强制转换到某个MyProperty数组的某个对象
生成的结果应实现此场景:
BindingSource.DataSource = GeneratedResult; //execute some code (from the get).
MyClass.MyProperty
在给出您的示例时没有意义,因此我担心任何答案都可能误解您的意图。你能澄清一下这个例子吗?你是说“…”=someMyClassInstance.myProperty`?经过编辑,使示例更有意义(是的,这就是我的意思)。通过编辑,这个句子片段指的是什么?“获取对MyClass.MyProperty实例的引用”我想返回bindingsoure真正绑定到的对象。不是属性返回的结果(数组)。如果我在public MyProperty[]MyProperty
中有一个getter,我希望再次调用它。因此,当我说BindingSource.DataSource=MyReflectionResult
时,get代码将重新运行。typeof(MyClass).GetProperty(“myProperty”,BindingFlags.Instance | BindingFlags.Public)。GetValue(Instance,null)
?这将执行属性的get处理程序。尽管如此,听起来您希望在myProperty发生更改时发生一个事件,请听一听。