Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

fluent interfaces and xml serialisation...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ollie - 04 Mar 2008 16:35 GMT
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?

Cheers in advance

Ollie
Jon Skeet [C# MVP] - 04 Mar 2008 16:45 GMT
> 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
[quoted text clipped - 3 lines]
> 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.

Signature

Jon Skeet - <skeet@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 - 04 Mar 2008 17:00 GMT
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

> > 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
[quoted text clipped - 10 lines]
> surprised if there weren't some way of intercepting the deserialization
> in the class itself.
Marc Gravell - 04 Mar 2008 20:51 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.