Friday, November 13, 2009
Tail recursion
Another nice one could be found here.
Serializing Dictionary to/from XML
Published 09 November 09 04:08 by Michael LehmanI spent a bit of time searching for the magic of how to use XmlSerialize with the Dictionary type this morning and thought I’d share the easy-to-use result:
Assuming you have an object, let’s say it’s called “data” that is of type Dictionary
, you can save it to an XML file whose name is contained in the string “dataName” like this: XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
XmlWriter writer = XmlWriter.Create(dataName, settings);
DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary));
serializer.WriteObject(writer, data);
writer.Close();(XmlWriterSettings is used to cause the resulting XML come out on human-readable multiple lines instead of all on one very long line.)
and read it back like this:
XmlReader reader = XmlReader.Create(dataName);
DataContractSerializer serializer = new DataContractSerializer(typeof(Dictionary)); result = (Dictionary
)serializer.ReadObject(reader);
reader.Close();
Thursday, November 12, 2009
Update manger thoughts
I also discovered that WSS web-services could be used for file copy.
Wednesday, November 11, 2009
Lectures on Physics:Tuva
http://research.microsoft.com/apps/tools/tuva/
New Mock/Stub Framework as part of Pex
Pex - Downloads - Microsoft Research: "Stubs framework, lightweight test stubs and detours for .NET"
AOP:AspectF
CodeProject: AspectF Fluent Way to Add Aspects for Cleaner Maintainable Code. Free source code and programming help: "AspectF"
AspectF.Define
.Log(Logger.Writer, "Inserting customer the easy way")
.HowLong(Logger.Writer, "Starting customer insert",
"Inserted customer in {1} seconds")
.Retry()
.Do(() =>
{
CustomerData data = new CustomerData();
data.Insert(firstName, lastName, age, attributes);
});