Skip to content

Instantly share code, notes, and snippets.

@stdray
Created March 14, 2015 00:49
Show Gist options
  • Select an option

  • Save stdray/dfbf05b8f3f64f6457cb to your computer and use it in GitHub Desktop.

Select an option

Save stdray/dfbf05b8f3f64f6457cb to your computer and use it in GitHub Desktop.
def makeDeserializer(types)
{
def mapRef = <[ $("map" : usesite)]>;
def mapExprs = types.Map(t => <[ $mapRef.Add($(t.Name), typeof($(ExpandFullName(t.FullName)))); ]>);
<[decl:
public module Deserializer
{
private map : Lazy[Dictionary[string, Type]] = Lazy(getMap, System.Threading.LazyThreadSafetyMode.PublicationOnly);
private getMap() : Dictionary[string, Type]
{
def $mapRef = Dictionary();
{..$mapExprs}
$mapRef
}
public Deserialize(name : string, content : System.Xml.Linq.XDocument) : object
{
XmlHelper.XDeserialize(content, map.Value[name]);
}
public DeserializeDocument(content : System.Xml.Linq.XDocument) : object
{
Deserialize(content.Root.Name.LocalName, content);
}
}
]>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment