I suggest you ...

traceof special word

One of biggest problems in computer programming is determining when a variable changes its value.
The typical problem is: “When X is changed so…” or “Before X is changed…”.
This is the main problem in bindings scenarios but also in a lot of other cases.

We can separate problem in two main problem:

1) When X is changed?
2) When A.B.C.D.E.X is changed?

At the moment the solution require to define a lot of redundant code.
Typically we must define an XProperty closely related to X property. If we want to trace A.B.C.D.E.X we must define the same pattern for all A,B,C,D,E,X property and add remove correctly event delegates on A,B,C,D,E,X changes.

Can c# compiler help to obtain great results with really simple code? I Think yes.

I think the solution starts from a mechanism that allow to look a variable name as a kind of pointer.

1) Suppose to add a special word as “traceoff” that return an TraceObject<T>, now suppose that we write:

var i = 10;
var t = traceof(i);
i = 20;
i = 0;

Now compiler can substitute this with:

var i = 10:
var t = new TraceOf<int>();
var c1 = 20
i = c1;
var c2 = 0
i = c2;

Look that can exists only one Tracker for same variable, so declaring two traceof for same variable compiler can use only one object.

2) Extending traceof to implicit properties can be immediate.

3) Exception when traced value is not a variable or a implicit property.

4) traceoff property chain. Now we can write:

var o = new X()
var t = traceoff(o.P);

Now compiler notify change to when o or P is assigned.
Look that now P can have an “Unassigned” value when o is set to null; So, in this case, the Canged/Changing eventarg must contains an “ValueContainer<T>” that can be empty or valued and value can be nut or not.

At the end we will can solve main problem simply writing:

var t = traceof(A.B.C.D.E.X);
t.ValueChanging += …
t.ValueChanged += …

and this will grant that a giant lot of con and bugs can be removed from each application.
finally c# will be the first language with a simple and powerful way to natural low level binding.

6 votes
Sign in
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Marcello shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →


Sign in
Password icon
Signed in as (Sign out)
  • Marcello commented  ·   ·  Flag as inappropriate

    > I suppose, this can be solved on a library level. I don't see a need to add this to the core language.

    No. Only clr know that a value is assigned. At the moment is not possible to access this invormation if value owner don't implements specific evets or other trace strategies.

  • Anonymous commented  ·   ·  Flag as inappropriate

    I suppose, this can be solved on a library level. I don't see a need to add this to the core language.

  • Marcello commented  ·   ·  Flag as inappropriate

    I hope that is evident that with this approach INotifyPropertyChanged problem (https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/2255378-inotifypropertychanged) will be obsolete because c# itself allow to track changes on all properties that implements or not INotifyPropertyChanged.

    In ex. Binding can ferify if the requested property implement INotifyPropertyChanged or can be traced. If not raise an error.

Feedback and Knowledge Base