New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add structured functional-style API over `WriteStart()/WriteEnd()` #631

Closed
Lingxi-Li opened this Issue Jul 8, 2016 · 0 comments

Comments

Projects
None yet
2 participants
@Lingxi-Li
Contributor

Lingxi-Li commented Jul 8, 2016

Paired WriteStart()/WriteEnd() calls are used in current writer API. Being totally free-style and non-structured, such API becomes cumbersome when writing complex and deeply nested payloads. The task is to add a layer over existing API and provide a structured functional-style paradigm. The following example illustrates the idea of the new API.

Using existing API:

writer.WriteStart(outer);
    writer.WriteStart(inner1);
    writer.WriteEnd();
    writer.WriteStart(inner2);
    writer.WriteEnd();
writer.WriteEnd();

Using new API:

writer.Write(outer, () => writer
    .Write(inner1)
    .Write(inner2));

This new API releases users from the burden of managing pairing/nesting of WriteStart()/WriteEnd() calls, and allows for cleaner user code. It also allows for fluent syntax.

@Lingxi-Li Lingxi-Li self-assigned this Jul 8, 2016

Lingxi-Li added a commit that referenced this issue Jul 12, 2016

Add structured functional-style writer API #631
1) Releases users from the burden of managing pairing/nesting of `WriteStart()/WriteEnd()` calls
2) Supports fluent syntax for writing

@Lingxi-Li Lingxi-Li closed this Jul 12, 2016

@LaylaLiu LaylaLiu removed the in-progress label Jul 12, 2016

@Lingxi-Li Lingxi-Li added improvement and removed feature labels Aug 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment