0

Show each return value in chained method call

HeadBurningMan 3 weeks ago in New features updated 3 weeks ago 1
var iWantMyLength = new MyClass() // class instance with a bunch of properties and field
    .SetMethod1(paramerter1) // some field changed compare to previous line
    .SetMethod2(paramerter2) // another difference
    .ToString() // exported string via override method
    .Trim() // remove not need space
    .Length; // get final string length and put into "iWantMyLength" make it int32

In this crap demo you can see I will meet three different class instance "snapshot"

a string, a trimmed string and a length.

The entire process is similar to "LINQ" but because it was actually not a LINQ,

Visual Studio itself, or OzCode visual studio extension will not display each return value.

Result in when I "step over", I only get final length...The entire calling process are lost.

If I have a bug, I must separate this statement into the following:

var wantMyLengthClass1 = new MyClass();

var setResult1Class1 = wantMyLengthClass1.Clone() // copy because class instance are reference
    .SetMethod1(paramerter1); // put into setResult1

var setResult2Class1 = wantMyLengthClass1.Clone()
    .SetMethod2(paramerter2); // i want to see the difference between calls

var getString1 = setResult2Class1.ToString(); // i want to see what is raw string
var getTrimmedString1 = getString1..Trim(); // i want to see difference after trim

var iWantMyLength1 = getString1.Length; // finally...

// I want more samples, so I have to...

var wantMyLengthClass2 ...
var setResult1Class2 ...
var setResult2Class2 ...
var getString2 ...
var getTrimmedString2 ...
var iWantMyLength2 ...

The fact is such statement are very annoying and will let you to think

why chaining method call feature even exist, without any kind of return value check.


So the idea is when step though a chained method call,

save each return value as a snapshot copy, display on magic glance HUD or something

Then the best is able to compare the snapshot values in different stage.

The class are basically keep returns itself like this:

public class MyClass
{
    public MyClass SetMethod1(paramerter)
    {
        // do something
        ...

        // this keyword point to the SetMethod1 running class instance
        return this;
    }

    public MyClass SetMethod2(paramerter)
    {
        // do something
        ...

        // same as above
        return this;
    }

    public new string ToString()
    {
        // convert private array to a comma separated string
        // this time, return type is not MyClass instance
        // and became .NET standard string
        return string.Join("," this.xyz);
    }
}