A clean way to automatically call one method after another?

Is it possible to develop a method so that it knows that it should automatically call the next method after exiting it?

In the following example, I have to call Refresh()for my form to be redrawn after this event. The problem is that it is ugly to trigger Refresh()after, for example, 20 different events that should update the form. eg

private void PriorityLine_Click(object sender, EventArgs e)
{
   _showPriorityLine = (_showPriorityLine) ? false : true;
  Refresh(); // Must call refresh for changes to take effect.
}

I assume that what I am looking for is some kind of signature that I can apply to the method to make it automatically connect to the next method, regardless of where it was called. eg,

(I know this is not syntactically correct.)

private void PriorityLine_Click(object sender, EventArgs e).Refresh()
{
   _showPriorityLine = (_showPriorityLine) ? false : true;
}

, . , , . , Refresh, . , Refresh , - , .

+5
7

, - Aspect Oriented Programming, , " " , AOP .Net?

+3
+1

, .

,

private bool _showPriorityLine;
private bool ShowPriorityLine
{
    get { return _showPriorityLine; }
    set
    {
        _showPriorityLine = value;
        Refresh();
    }
}

private void PriorityLine_Click(object sender, EventArgs e)
{
    ShowPriorityLine = !ShowPriorityLine;
}

, , , , .

0

, , " " - , , MSDN.

, , , , , .

  private List<string> _refreshProps = new List<string>();
  private bool _showPriority;

  public void Form()
  {
      _refreshProps.Add("ShowPriority");
      ... etc
  }

  // only implement properties like this that need some extra work done
  public bool ShowPriority
  {
      get { return _showPriority; }
      set
      {
          if (_showPriority != value)
          {
              _showPriority = value;
              // Call OnPropertyChanged whenever the property is updated
              OnPropertyChanged("ShowPriority");
          }
      }
  }

  // basic property that doesn't require anything extra
  public bool AnotherProperty { get; set; }

  public void Refresh()
  {
      // refresh the form
  }

  protected void OnPropertyChanged(string name)
  {
      if (_refreshProps.Contains(name))
          Refresh();
  }

, "" , OnPropertyChanged.

0

Refresh, Invalidate. Windows. Invalidate . WM_PAINT ( root DispatchMessage, ).

0

, Refresh .

-1

- :

private void RefreshAfter(Action action)
    {
        action();
        Refresh();
    }

:

    private void DoSomeUiShiznit(Action action)
    {
        action();
        // other parts of the code don't realize that Refresh has to be called.
        // But that cool. I got it covered.
        Refresh();
    }

    private void PriorityLine_Click(object sender, EventArgs e)
    {
        DoSomeUiShiznit(() => { _showPriorityLine = !_showPriorityLine; });
    }

UPDATE is just a message to voters:

Some of you are too blind to see that this is not all that is different from:

[SomeRefreshAttribute]  
private void PriorityLine_Click(object sender, EventArgs e)  
{
    _showPriorityLine = !_showPriorityLine;  
}  

Except that it is simpler and does not require adding another environment to the solution. And yet another answer, suggesting not to go down as much, voted!

What is wrong with you?

-5
source

All Articles