0

Example:

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;

Is there a way, maybe using reflection (or inheriting from BindingSource), to get a reference to MyClass.MyProperty instance, instead of an object containg just a MyProperty[].

BindingSource.DataSource returns just that, some object, that can be cast to some MyProperty array.

The generated result should achieve this scenario:

BindingSource.DataSource = GeneratedResult;  //execute some code (from the get).
JJ_Jason
  • 349
  • 8
  • 24
  • `MyClass.MyProperty` does not make sense given your example, therefore I worry that any answer could misunderstand your intent. Can you clarify the example? Did you mean ` ... = someMyClassInstance.myProperty` ? – Marc Gravell Sep 09 '12 at 15:24
  • Edited, to make the example have more sense (yes, that's what i meant). – JJ_Jason Sep 09 '12 at 15:24
  • 1
    With the edit, still, what does this sentence-fragment refer to? "get a reference to MyClass.MyProperty instance" – Marc Gravell Sep 09 '12 at 15:26
  • I would like to return an object to which the bindingsoure is really bound to. Not the result that the property returns (the array). If I have a getter in `public MyProperty[] myProperty`, i would like it to be called again. So when i say `BindingSource.DataSource = MyReflectionResult`, the get code would re-run. – JJ_Jason Sep 09 '12 at 15:28
  • `typeof(MyClass).GetProperty("myProperty", BindingFlags.Instance | BindingFlags.Public).GetValue(instance, null)`? This will execute the get handler of the property. Although, it rather sounds like you want an *event* for when myProperty *changes*, and listen to that. – Patrick Sep 09 '12 at 16:04
  • Yes. But what i would like to get as the result is `MyClass` (and `"MyProperty"`). So then I could do, what you just did there. – JJ_Jason Sep 09 '12 at 16:10

0 Answers0