48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using Humanizer;
|
|
using MycroForge.CLI.Extensions;
|
|
|
|
namespace MycroForge.CLI.Commands;
|
|
|
|
public class FullyQualifiedName
|
|
{
|
|
public string Namespace { get; }
|
|
public string PascalizedName { get; }
|
|
public string SnakeCasedName { get; }
|
|
|
|
public string FilePath =>
|
|
string.IsNullOrEmpty(Namespace.Trim())
|
|
? SnakeCasedName
|
|
: Path.Join(Namespace, SnakeCasedName);
|
|
|
|
public bool HasNamespace => Namespace.Length > 0;
|
|
|
|
|
|
public FullyQualifiedName(string name)
|
|
{
|
|
var path = string.Empty;
|
|
|
|
if (name.Split(':').Select(s => s.Trim()).ToArray() is { Length: 2 } fullName)
|
|
{
|
|
path = fullName[0];
|
|
name = fullName[1];
|
|
}
|
|
|
|
Namespace = path;
|
|
PascalizedName = name.Pascalize();
|
|
SnakeCasedName = SnakeCase(name);
|
|
}
|
|
|
|
public string GetImportPath(params string[] root)
|
|
{
|
|
if (root.Length == 0)
|
|
return string.Join('.', FilePath).SlashesToDots();
|
|
|
|
var importRoot = string.Join('.', root);
|
|
|
|
return string.Join('.', SnakeCase(importRoot), FilePath).SlashesToDots();
|
|
}
|
|
|
|
private static string SnakeCase(string value) => value.Underscore().ToLower();
|
|
|
|
// private static string SlashesToDots(string value) => value.Replace('\\', '.').Replace('/', '.');
|
|
} |