diff --git a/Smithy.CSharpGenerator/Utils/NamingUtils.cs b/Smithy.CSharpGenerator/Utils/NamingUtils.cs index 4d6a428..ccec8c0 100644 --- a/Smithy.CSharpGenerator/Utils/NamingUtils.cs +++ b/Smithy.CSharpGenerator/Utils/NamingUtils.cs @@ -3,8 +3,7 @@ namespace Smithy.CSharpGenerator.Utils { public static class NamingUtils - { - public static string PascalCase(string id) + { public static string PascalCase(string id) { if (string.IsNullOrEmpty(id)) return id; var parts = id.Split(new[] { '.', '#', '_' }, System.StringSplitOptions.RemoveEmptyEntries); @@ -18,5 +17,22 @@ public static string PascalCase(string id) } return sb.ToString(); } + + public static string KebabCase(string id) + { + if (string.IsNullOrEmpty(id)) return id; + var sb = new StringBuilder(); + + for (int i = 0; i < id.Length; i++) + { + if (i > 0 && char.IsUpper(id[i])) + { + sb.Append('-'); + } + sb.Append(char.ToLower(id[i])); + } + + return sb.ToString(); + } } } diff --git a/Smithy.Model/SmithyModelExtensions.cs b/Smithy.Model/SmithyModelExtensions.cs new file mode 100644 index 0000000..d4337ae --- /dev/null +++ b/Smithy.Model/SmithyModelExtensions.cs @@ -0,0 +1,40 @@ +using System; +using System.Linq; + +namespace Smithy.Model +{ + /// + /// Extension methods for SmithyModel to simplify shape access + /// + public static class SmithyModelExtensions + { + /// + /// Get a shape by its ID from the model + /// + /// The type of shape to retrieve + /// The Smithy model + /// The ID of the shape to retrieve + /// The shape with the specified ID, or null if not found + public static T GetShape(this SmithyModel model, string shapeId) where T : Shape + { + if (model == null || string.IsNullOrEmpty(shapeId)) + return null; + + return model.Shapes.OfType().FirstOrDefault(s => s.Id == shapeId); + } + + /// + /// Get a shape by its ID from the model + /// + /// The Smithy model + /// The ID of the shape to retrieve + /// The shape with the specified ID, or null if not found + public static Shape GetShape(this SmithyModel model, string shapeId) + { + if (model == null || string.IsNullOrEmpty(shapeId)) + return null; + + return model.Shapes.FirstOrDefault(s => s.Id == shapeId); + } + } +}