Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#,BindingSource和DataSource_C#_Reflection_Bindingsource - Fatal编程技术网

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发生更改时发生一个事件,请听一听。