Home > Net >  Consult the c # how to monitor variables, at the beginning of the reference variable change events?
Consult the c # how to monitor variables, at the beginning of the reference variable change events?

Time:11-22

Find are all attributes of use get trigger event, but this way to meet a read-only external class time is not very practical,
Now have a Isenabled property in reference, I think when he become false bright red light on the UI, true green light, how should solve?

CodePudding user response:

, has set up a night, hope ace grant instruction

CodePudding user response:

This doesn't work, either with attributes, or with the entrusted/interface

CodePudding user response:

I seldom play the analogy in response to a technical problem, but the problem is simple, is also good for analogy, exception,

If a man he changed his status, such as he uncomfortable, unhappy, he doesn't tell you, what would you do? Is only one way, it is often to check on him, you are in the treatment of the variables, only this way,

CodePudding user response:

No new under the sun, you want the MVVM (net itself also supports MVVM, just need other implement InotifyPropertychanged)
Look at the following
https://github.com/DMQ/mvvm

Js is interpreted, of course, can dynamically coverage, I also don't want to waste his brains, fuck hijacked, you first use the simplest the most low, the interval timer implementation (.net is, after all, half the compiled to run-time hijacked than js, this kind of thing you have the ability to make talking)

CodePudding user response:

Don't waste the brains method and 100 ms examination time,
 using System; 
using System.Collections.Generic;
using System.ComponentModel;
Using System. The Data;
Using System. Drawing;
Using System. Linq;
Using System. Reactive. Linq.
Using System.Runtime.Com pilerServices;
using System.Text;
Using System. The Threading;
Using System. The Threading. The Tasks;
Using System. Windows. Forms;
Using WindowsFormsApp1. Annotations;

The namespace WindowsFormsApp1
{
Public partial class Form3: Form
{
Public Form3 ()
{
InitializeComponent ();
}

Private void Form3_Load (object sender, EventArgs e)
{
;
Var t=new test ();
NotifyPro (t, p=& gt; P.A.)
ObserveOn (SynchronizationContext. Current)
The Subscribe (p=& gt; {this. Label1. Text=p; });
}

Private IObservable NotifyPro (T1 obj, Func Func)
{
Return observables. Interval (TimeSpan. FromMilliseconds (100))
. Select (p=& gt; Func (obj))
DistinctUntilChanged ();
}
}

Public class test
{
The public test ()
{
Task. The Run (async ()=& gt;
{
While (true)
{
Enclosing A=A DateTime. Now. The ToString ();
Await Task. Delay (1000);
}

});
}


Public string A {get; The set; }
}


}



Can emit nevertheless premise is virtual, so we can dynamic coverage, it is also a lot of dynamic proxy and aop interception why ask you to write virtual and the reason of the interface, the interface also show cover off
The runtime IL can hijack but need you careful with
Therefore, comprehensive consideration, here to choose the most low, check regularly,

CodePudding user response:

C # can't monitor variables ", the standard is encapsulated in the attribute, trigger events, in. Netframework frame system are often used in INotifyPropertychanged interface, or use ObservableCollection<> Type and so on mechanism to realize their object listening,

CodePudding user response:

"Take it for granted way" looks tall shangdi play bottom, performance actually, encapsulation, stability, adjustable device debugging, engineering aspects, such as can compile error correction are amateur instead, so the real engineering is to balance, should pay attention to the contract (interface) oriented programming, and don't take it for granted to pursue what invasion method,
  •  Tags:  
  • C#
  • Related