mirror of
https://github.com/Tribufu/TribufuDotNet
synced 2026-08-07 20:06:22 +00:00
* Migrate to new tribufu project structure * Update .gitignore * Remove old api files * Update Directory.Build.props * Rename solution
35 lines
974 B
C#
35 lines
974 B
C#
// Copyright (c) Tribufu. All Rights Reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
using Newtonsoft.Json.Serialization;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace Tribufu.Serialization
|
|
{
|
|
public class NetworkAwareSnakeCaseNamingStrategy : SnakeCaseNamingStrategy
|
|
{
|
|
private static readonly string[] KnownAcronyms = new string[] { "IPv4", "IPv6" };
|
|
|
|
protected override string ResolvePropertyName(string name)
|
|
{
|
|
if (string.IsNullOrEmpty(name))
|
|
{
|
|
return name;
|
|
}
|
|
|
|
foreach (var acr in KnownAcronyms)
|
|
{
|
|
name = Regex.Replace(name, acr, acr.ToLower());
|
|
}
|
|
|
|
var snake = base.ResolvePropertyName(name);
|
|
foreach (var acr in KnownAcronyms)
|
|
{
|
|
var lower = acr.ToLower();
|
|
snake = snake.Replace(lower.Replace("_", ""), lower);
|
|
}
|
|
|
|
return snake;
|
|
}
|
|
}
|
|
}
|