Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: fluent interfaces and xml serialisation...

0 views
Skip to first unread message

Jon Skeet [C# MVP]

unread,
Mar 4, 2008, 11:45:52 AM3/4/08
to
Ollie <ollie_...@hotmail.com> wrote:
> I'm thinking of adding a more fluent interface to a set C# class in my
> current domain, the only thing that is causing me a dilemma is the fact that
> the classes need to support serialisation (xml), this means they will have 2
> ways to set properties and I don't generally like this...
>
> Does anyone have any experience with supporting a a fluent interface style
> on .Net classes that support xml serialisation?

The way I see it, the issue isn't supporting a fluent interface - it's
having mutable types. The two can coexist.

I'm afraid I don't know very much about XML Serialization, but I'd be
surprised if there weren't some way of intercepting the deserialization
in the class itself.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Ollie

unread,
Mar 4, 2008, 12:00:01 PM3/4/08
to
hello Jon,

I'm sure (in fact I know) you can control the xml serialisation at a more
fine grained level but I'm trying not to go down that road at the moment...

Cheers

Ollie

Marc Gravell

unread,
Mar 4, 2008, 3:51:49 PM3/4/08
to
If you want to go with a fluent approach rather than getter/setter,
you'd need to handle IXmlSerializable yourself; note that you'd also
lose automatic schema visibility, and the ability to do standard data-
binding. And probably a few other ComponentModel things that I'm
forgetting. This sounds unncessarily painful.

Can I ask what the driver is for fluent in this case? If the problem
is primarily at instantiation, then perhaps consider C# 3 object
initializers? i.e.

Foo foo = new Foo {Width = 100, Length = 20, Name = "Fred", Foo =
"Bar", When = DateTime.Now };

Marc

0 new messages