CsQuery icon indicating copy to clipboard operation
CsQuery copied to clipboard

DomElement fluent API

Open stijnherreman opened this issue 11 years ago • 3 comments

Are there any plans to support a fluent API for DomElement (and similar classes)?

Instead of

var wrapper_1 = DomElement.Create("div");
wrapper_1.AddClass("foo");

var wrapper_2 = DomElement.Create("div");
wrapper_2.AddClass("bar");

wrapper_1.AppendChild(wrapper_2);

I'd like to write

var wrapper = DomElement.Create("div")
    .AddClass("foo")
    .AppendChild(DomElement.Create("div")
        .AddClass("bar")
        );

stijnherreman avatar May 16 '13 13:05 stijnherreman

This is definitely an oversight in the way I implemented some of the DOM methods. This would be easy to fix, the only problem is that it would break binary compatibility, see: http://stackoverflow.com/questions/1456785/a-definite-guide-to-api-breaking-changes-in-net

There are a lot of other changes I would like to make to the DOM model that I've held off on for this reason. I'd planned to have all this be part of 2.0 which would also be created as a cross-platform library. This could be a while off though.

I'm thinking the way to go is to start a pre-2.0 branch in which I can start making API changes like this in the meantime without breaking things for existing users, which I will put out of nuget as a prereleases.

jamietre avatar May 16 '13 13:05 jamietre

That's a quick response :) I'll be looking forward to future releases.

I might open pull requests in the future, but I've only started working with CsQuery today so I'm still figuring out the basics.

stijnherreman avatar May 16 '13 13:05 stijnherreman

By all means! I welcome any and all contributions, it's a big project.

jamietre avatar May 16 '13 15:05 jamietre