Skip to content

Commit

Permalink
enable OptIn functionality for serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
joekolodz committed Mar 30, 2024
1 parent 35b54ca commit 6e82b64
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/CustomSierraJsonConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,10 @@ public void WriteJson(object value)

private static void SerializeButtonAction(ButtonAction action)
{
var propList = typeof(ButtonAction).GetProperties();
var propList = SierraJsonAttributes.GetSerializableProperties(action);
Serializer.WriteObjectStart();
foreach (var prop in propList)
{
if (prop.GetCustomAttributes(true).Any(x => x is SierraJsonIgnore)) continue;

var value = prop.GetValue(action);

if (prop.Name == nameof(action.IsKeyUp) && (bool)prop.GetValue(action) == false) continue;
Expand All @@ -126,12 +124,10 @@ private static void SerializeButtonAction(ButtonAction action)

private static void SerializeButton(HOTASButton button)
{
var propList = typeof(HOTASButton).GetProperties();
var propList = SierraJsonAttributes.GetSerializableProperties(button);
Serializer.WriteObjectStart();
foreach (var prop in propList)
{
if (prop.GetCustomAttributes(true).Any(x => x is SierraJsonIgnore)) continue;

var value = prop.GetValue(button);

// if (prop.Name == nameof(button.ShiftModePage) && (int)prop.GetValue(button) == 0) continue;
Expand All @@ -147,12 +143,10 @@ private static void SerializeButton(HOTASButton button)

private static void SerializeAxis(HOTASAxis axis)
{
var propList = typeof(HOTASAxis).GetProperties();
var propList = SierraJsonAttributes.GetSerializableProperties(axis);
Serializer.WriteObjectStart();
foreach (var prop in propList)
{
if (prop.GetCustomAttributes(true).Any(x => x is SierraJsonIgnore)) continue;

var value = prop.GetValue(axis);

if (prop.Name == nameof(axis.IsDirectional) && (bool)prop.GetValue(axis) == true) continue;
Expand All @@ -167,12 +161,10 @@ private static void SerializeAxis(HOTASAxis axis)

private static void SerializeCatalogActionItem(ActionCatalogItem item)
{
var propList = typeof(ActionCatalogItem).GetProperties();
var propList = SierraJsonAttributes.GetSerializableProperties(item);
Serializer.WriteObjectStart();
foreach (var prop in propList)
{
if (prop.GetCustomAttributes(true).Any(x => x is SierraJsonIgnore)) continue;

var value = prop.GetValue(item);

Serializer.WriteKeyValue(prop.Name, value);
Expand Down

0 comments on commit 6e82b64

Please sign in to comment.