deCast - Dynamic Xml with C# 4.0
- Posted: Jan 26, 2009 at 3:32 AM
- 15,624 Views
- 4 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
This is pretty nice but broken. There's too much magic going on. The XML GI syntax (and still more the ns'd GI syntax) does not match up with C# method name syntax. In particular C# method names are far more restricted than XML (namespace) names, they cannot express them. Now adding magic names such as Nodes, Parent, etc. will only compound the problem. What happens if a document actually happens to have an element called Parent or Nodes? So based on a quick review, this approach does not appear sound, as much as I love syntactic sugar.
Now the idea to abstract over attribute and element names is quite sweet. I like the idea and this is also the approach that RDF/XML takes. It just needs to be an explicit abstraction taken by the client not built into the API as a default, thus projecting that assumption onto all existing XML.
As a way to illustrate how dynamic is useful this is not so bad - except it, in my oppinion, teaches an unsound practice for dealing with XML; at least it is not general-purpose. One has to know a priori that such and such name collisions (Parent, Nodes?) will not occur (there goes extensibility) and that cannot express such and such names (XML name syntax, including names in popular XML dialects such as XSLT, where you can have: xslt:value-of).
Any chance you could post the sample implementation of this code please?
Thanks - this look good.
The screencast goes over your fun little XML DSL but doesn't ACTUALLY talk about how to take advantage of any of C# 4.0's dynamic objects.
Very neat, but now I have to search online for documentation on DynamicObject and methods like GetMember, assuming those are part of the CLR or DLR and not something you wrote.
Could you please post the code from the episode so people can take a look at the actual code to figure out how to take advantage of these new features?
DynamicObject reference: http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject.aspx
A blog post that shows example implementations of TryInvokeMember, TryGetMember, TrySetMember, and more: http://weblogs.asp.net/dixin/archive/2010/06/08/a-todynamic-extension-method-for-fluent-reflection.aspx
Remove this comment
Remove this thread
close