Last active
March 15, 2019 13:07
-
-
Save oledid/01edc631fdf63b43fe223d6fa9c3651d to your computer and use it in GitHub Desktop.
Serialize LLBLGEN Entity to json without LLBLGEN-specific fields
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
using System.Collections.Generic; | |
using System.Dynamic; | |
using Newtonsoft.Json; | |
using Your.ORM.EntityClasses; // <- replace | |
namespace Your.Namespace // <- | |
{ | |
public static class CommonEntityBaseExtensions | |
{ | |
/// <summary> | |
/// Serializes EntityFields as json (and ignores other LLBLGEN-specific fields) | |
/// </summary> | |
public static string ToJson(this CommonEntityBase entity) | |
{ | |
if (entity == null) | |
return null; | |
dynamic expando = new ExpandoObject(); | |
foreach (var field in entity.Fields) | |
{ | |
((IDictionary<string, object>)expando).Add(field.Name, field.CurrentValue); | |
} | |
return JsonConvert.SerializeObject(expando); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment