Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created March 1, 2013 22:32
Show Gist options
  • Save thecodejunkie/5068466 to your computer and use it in GitHub Desktop.
Save thecodejunkie/5068466 to your computer and use it in GitHub Desktop.
Modifying Nancy.Serializers.JsonNet to support customization through either auto-discovery or explicit settings
public static JsonSerializer Serializer;
public JsonNetSerializer()
{
Serializer = GetJsonSerializer();
}
private static JsonSerializer GetJsonSerializer()
{
if (Serializer != null)
{
return Serializer;
}
var serializerType = AppDomainAssemblyTypeScanner
.Types
.Where(x => x != typeof(JsonSerializer)).SingleOrDefault(x => (typeof(JsonSerializer).IsAssignableFrom(x)));
return (serializerType != null) ? (JsonSerializer)Activator.CreateInstance(serializerType) : new JsonSerializer();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment