Guest User

Untitled

a guest
Jan 22nd, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. public class MyBindingSource : BindingSource
  2. {
  3.  
  4. private MethodInfo MyMethod= null;
  5.  
  6. protected override void OnBindingComplete(BindingCompleteEventArgs e)
  7. {
  8. this.MyMethod = GetMyMethod();
  9. //MyMethod is not null here
  10. }
  11.  
  12. void UseMyMethod (object value)
  13. {
  14. MyMethod.Invoke(SomeObject, new object[] { value });
  15. //MyMethod is null here, exception thrown.
  16. }
  17.  
  18. }
  19.  
  20. public class MyBindingSource : BindingSource
  21. {
  22. private MethodInfo _myMethod = null;
  23.  
  24. private MethodInfo MyMethod
  25. {
  26. get
  27. {
  28. if(_myMethod != null) return _myMethod;
  29.  
  30. _myMethod = GetMyMethod();
  31. return _myMethod;
  32. }
  33. }
  34.  
  35. protected override void OnBindingComplete(BindingCompleteEventArgs e)
  36. {
  37. }
  38.  
  39. void UseMyMethod (object value)
  40. {
  41. MyMethod.Invoke(SomeObject, new object[] { value });
  42. }
  43. }
Add Comment
Please, Sign In to add comment