Created
March 1, 2013 22:32
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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