Skip to content

Commit

Permalink
Moved Json converters to separate folder (#509)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Petrochuk (from Dev Box) <[email protected]>
  • Loading branch information
petrochuk and anpetroc authored Jan 21, 2024
1 parent c397208 commit f0610c6
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Globalization;
using System.Text.Json;

namespace Microsoft.AppMagic.Persistence.Converters;
namespace Microsoft.PowerPlatform.Formulas.Tools.JsonConverters;

internal class JsonDateTimeConverter : System.Text.Json.Serialization.JsonConverter<DateTime>
{
Expand Down
20 changes: 20 additions & 0 deletions src/PAModel/JsonConverters/JsonDoubleToIntConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json;
using System.Text.Json.Serialization;

namespace Microsoft.PowerPlatform.Formulas.Tools.JsonConverters;

public class JsonDoubleToIntConverter : JsonConverter<int>
{
public override int Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return reader.TryGetDouble(out var value) ? Convert.ToInt32(value) : reader.GetInt32();
}

public override void Write(Utf8JsonWriter writer, int value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value, options);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System.Text.Json;

namespace Microsoft.AppMagic.Persistence.Converters;
namespace Microsoft.PowerPlatform.Formulas.Tools.JsonConverters;

internal class JsonNullableDateTimeConverter : System.Text.Json.Serialization.JsonConverter<DateTime?>
{
Expand Down Expand Up @@ -32,4 +32,4 @@ public override void Write(
if (dateTimeValue.HasValue)
writer.WriteStringValue(JsonDateTimeConverter.WriteDate(dateTimeValue.Value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System.Text.Json;

namespace Microsoft.AppMagic.Persistence.Converters;
namespace Microsoft.PowerPlatform.Formulas.Tools.JsonConverters;

/// <summary>
/// Used to serialize and deserialize <see cref="Version"/>
Expand Down
9 changes: 8 additions & 1 deletion src/PAModel/Model/Control.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the MIT License.

using System.Diagnostics;
using System.Text.Json.Serialization;
using Microsoft.PowerPlatform.Formulas.Tools.JsonConverters;
using YamlDotNet.Serialization;

namespace Microsoft.PowerPlatform.Formulas.Tools.Model;
Expand All @@ -16,7 +18,7 @@ public Control()

public Control(ControlEditorState editorState)
{
EditorState = editorState;
EditorState = editorState ?? throw new ArgumentNullException(nameof(editorState));
Name = editorState.Name;

if (editorState.Children != null)
Expand All @@ -36,6 +38,11 @@ public Control(ControlEditorState editorState)

public string Name { get; init; }

public string Type { get; set; }

[JsonConverter(typeof(JsonDoubleToIntConverter))]
public int Index { get; set; }

public IList<Control> Controls { get; init; }

public IDictionary<string, object> Properties { get; init; }
Expand Down
6 changes: 3 additions & 3 deletions src/PAModel/Utility/Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using Microsoft.AppMagic.Persistence.Converters;
using Microsoft.PowerPlatform.Formulas.Tools.Schemas;
using Microsoft.PowerPlatform.Formulas.Tools.Utility;
using System.IO;
using System.IO.Compression;
using System.Linq;
Expand All @@ -12,6 +9,9 @@
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.PowerPlatform.Formulas.Tools.JsonConverters;
using Microsoft.PowerPlatform.Formulas.Tools.Schemas;
using Microsoft.PowerPlatform.Formulas.Tools.Utility;

[assembly: InternalsVisibleTo("PAModelTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: InternalsVisibleTo("PASopa, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
Expand Down

0 comments on commit f0610c6

Please sign in to comment.