jamietre / CsQuery

CsQuery is a complete CSS selector engine, HTML parser, and jQuery port for C# and .NET 4.
Other
1.15k stars 249 forks source link

DomElement fluent API #101

Closed stijnherreman closed 4 months ago

stijnherreman commented 11 years ago

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")
        );
jamietre commented 11 years ago

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.

stijnherreman commented 11 years ago

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.

jamietre commented 11 years ago

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