BryanWilhite / SonghayCore

core reusable, opinionated concerns for *all* 🧐 of my C# projects
http://songhayblog.azurewebsites.net/
MIT License
1 stars 0 forks source link

move Newtsonsoft concerns to a new package `SonghayCore.Newtonsoft` #135

Closed BryanWilhite closed 2 years ago

BryanWilhite commented 2 years ago

even though this is annoying and tedious adding this new package, SonghayCore.Newtonsoft, is a time-saving compromise compared to weeding out all of my Newtonsoft investments in one go

ideally this netstandard2.0 package will not depend on SonghayCore and should freeze in time or be locked in the Newtonsoft time frame

BryanWilhite commented 2 years ago

according to https://github.com/dotnet/runtime/issues/30180#issuecomment-557782346, [DataContract(Name = "opml")] is the equivalent of [JsonObject("opml")]

<| @layomia

BryanWilhite commented 2 years ago

ITemporalExtensions.ToJObject will be removed from the Core:

/// <summary>
/// Converts the specified <see cref="ITemporal"/> data
/// to <see cref="JObject"/>.
/// </summary>
/// <param name="data">the <see cref="ITemporal"/> data</param>
/// <param name="useJavaScriptCase">when <c>true</c> use snakecase</param>
/// <typeparam name="TData">a type derived from <see cref="ITemporal"/></typeparam>
public static JObject ToJObject<TData>(this ITemporal data, bool useJavaScriptCase) where TData : class, ITemporal
{
    if (data == null) return null;

    var settings = JsonSerializationUtility
        .GetConventionalResolver<TData>(useJavaScriptCase)
        .ToJsonSerializerSettings()
        .WithConventionalSettings()
        ;

    var jO = JObject.FromObject(data, JsonSerializer.Create(settings));

    return jO;
}
BryanWilhite commented 2 years ago

new repo: https://github.com/BryanWilhite/SonghayCore.Newtonsoft :octocat: ✨