diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-12-31 14:15:49 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2018-12-31 14:15:49 +0200 |
| commit | 650af0554b902837f8e146d690aca24e4f60ec29 (patch) | |
| tree | 30f3795d9579129395fd987c3e790ce33181c0e5 /Software/Visual_Studio/Tango.Core | |
| parent | cfe28eaf0adcd54776c0a369210e6f7b4bca9558 (diff) | |
| download | Tango-650af0554b902837f8e146d690aca24e4f60ec29.tar.gz Tango-650af0554b902837f8e146d690aca24e4f60ec29.zip | |
Removed Default configuration from machine version.
Implemented custom ToJson for observables.
Implemented Apply & Create prototype machine for machine version.
Diffstat (limited to 'Software/Visual_Studio/Tango.Core')
3 files changed, 59 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Tango.Core/Json/IJsonSerializationController.cs b/Software/Visual_Studio/Tango.Core/Json/IJsonSerializationController.cs new file mode 100644 index 000000000..f703a8863 --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Json/IJsonSerializationController.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Core.Json +{ + /// <summary> + /// Represents an object that defines which properties should not be serialized with the Json serializer. + /// </summary> + public interface IJsonSerializationController + { + /// <summary> + /// Gets the properties to ignore. + /// </summary> + /// <returns></returns> + List<String> GetIgnoreProperties(); + } +} diff --git a/Software/Visual_Studio/Tango.Core/Json/SerializationControllerContractResolver.cs b/Software/Visual_Studio/Tango.Core/Json/SerializationControllerContractResolver.cs new file mode 100644 index 000000000..702d51ddf --- /dev/null +++ b/Software/Visual_Studio/Tango.Core/Json/SerializationControllerContractResolver.cs @@ -0,0 +1,36 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.Core.Json +{ + public class SerializationControllerContractResolver : DefaultContractResolver + { + private List<String> _ignoreProperties = new List<string>(); + + protected override JsonObjectContract CreateObjectContract(Type objectType) + { + _ignoreProperties = new List<string>(); + + if (typeof(IJsonSerializationController).IsAssignableFrom(objectType)) + { + _ignoreProperties = (Activator.CreateInstance(objectType) as IJsonSerializationController).GetIgnoreProperties(); + } + return base.CreateObjectContract(objectType); + } + + protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) + { + var props = _ignoreProperties.ToList(); + JsonProperty property = base.CreateProperty(member, memberSerialization); + property.Ignored = false; + property.ShouldSerialize = (x) => !props.Contains(property.PropertyName); + return property; + } + } +} diff --git a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj index 8ed2c695b..5bfe3ab79 100644 --- a/Software/Visual_Studio/Tango.Core/Tango.Core.csproj +++ b/Software/Visual_Studio/Tango.Core/Tango.Core.csproj @@ -86,7 +86,9 @@ <Link>GlobalVersionInfo.cs</Link> </Compile> <Compile Include="IO\KnownFolders.cs" /> + <Compile Include="Json\IJsonSerializationController.cs" /> <Compile Include="Json\ProtobufContractResolver.cs" /> + <Compile Include="Json\SerializationControllerContractResolver.cs" /> <Compile Include="Threading\TaskSequencer.cs" /> <Compile Include="Threading\ThreadFactory.cs" /> <Compile Include="Threading\TimeoutTask.cs" /> @@ -193,7 +195,7 @@ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <ProjectExtensions> <VisualStudio> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> <Import Project="..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" /> |
