Created
June 16, 2012 21:03
-
-
Save dax70/2942507 to your computer and use it in GitHub Desktop.
JsonNetResult Logic
This file contains 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
// Data (like the default JsonResult) is the Model being serialized. | |
Type type = this.Data.GetType(); | |
// Wrap Enumerables to avoid potential Json Hijacking. | |
if (TypeHelper.TryWrappingForIEnumerableGenericOrSame(ref type)) | |
{ | |
this.Data = TypeHelper.GetTypeRemappingConstructor(type).Invoke(new object[] { this.Data }); | |
} | |
using (JsonTextWriter jsonTextWriter = new JsonTextWriter(response.Output) { CloseOutput = false }) | |
{ | |
var serializer = JsonSerializer.Create(this.SerializerSettings); | |
serializer.Serialize(jsonTextWriter, this.Data); | |
jsonTextWriter.Flush(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment