diff options
| author | Shlomo Hecht <shlomo@twine-s.com> | 2018-05-02 17:36:54 +0300 |
|---|---|---|
| committer | Shlomo Hecht <shlomo@twine-s.com> | 2018-05-02 17:36:54 +0300 |
| commit | ee697f7a3350d0a97bddee4de3a2ae4f9d285052 (patch) | |
| tree | 2dc2e3bb811b0d89a3c4c51801c1572966fcee7c /Software/Visual_Studio/Tango.Core/Json | |
| parent | 73c4b814f1f28170ae72723568189096413c3564 (diff) | |
| download | Tango-ee697f7a3350d0a97bddee4de3a2ae4f9d285052.tar.gz Tango-ee697f7a3350d0a97bddee4de3a2ae4f9d285052.zip | |
merge
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/Json')
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Json/DynamicContractResolver.cs | 30 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.Core/Json/HtmlContractResolver.cs | 39 |
2 files changed, 69 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Core/Json/DynamicContractResolver.cs b/Software/Visual_Studio/Tango.Core/Json/DynamicContractResolver.cs new file mode 100644 index 000000000..293b6947f --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Json/DynamicContractResolver.cs @@ -0,0 +1,30 @@ +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using System.Reflection; + +namespace Tango.Core.Json +{ + public class DynamicContractResolver : DefaultContractResolver + { + private List<String> _ignoreProperties; + + public DynamicContractResolver(params String[] ignoreProperties) + { + _ignoreProperties = ignoreProperties.ToList(); + } + + protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) + { + JsonProperty property = base.CreateProperty(member, memberSerialization); + + property.ShouldSerialize = (x) => !_ignoreProperties.Contains(property.PropertyName); + + return property; + } + } +} diff --git a/Software/Visual_Studio/Tango.Core/Json/HtmlContractResolver.cs b/Software/Visual_Studio/Tango.Core/Json/HtmlContractResolver.cs new file mode 100644 index 000000000..c4affd3ad --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Json/HtmlContractResolver.cs @@ -0,0 +1,39 @@ +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Newtonsoft.Json; +using System.Reflection; + +namespace Tango.Core.Json +{ + public class HtmlContractResolver : DefaultContractResolver + { + private List<String> _ignoreProperties; + + public HtmlContractResolver(params String[] ignoreProperties) + { + if (ignoreProperties != null) + { + _ignoreProperties = ignoreProperties.ToList(); + } + else + { + _ignoreProperties = new List<string>(); + } + } + + protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) + { + JsonProperty property = base.CreateProperty(member, memberSerialization); + + property.ShouldSerialize = (x) => !_ignoreProperties.Contains(property.PropertyName); + + property.PropertyName = "<b>" + property.PropertyName.Replace("\"", "") + "<b/>"; + + return property; + } + } +} |
