| | | 1 | | using System.Collections.Generic; |
| | | 2 | | |
| | | 3 | | namespace NexusLabs.Needlr.Generators.Models; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Information about a discovered Provider (from [Provider] attribute). |
| | | 7 | | /// </summary> |
| | | 8 | | internal readonly struct DiscoveredProvider |
| | | 9 | | { |
| | | 10 | | public DiscoveredProvider( |
| | | 11 | | string typeName, |
| | | 12 | | string assemblyName, |
| | | 13 | | bool isInterface, |
| | | 14 | | bool isPartial, |
| | | 15 | | IReadOnlyList<ProviderPropertyInfo> properties, |
| | | 16 | | string? sourceFilePath = null) |
| | | 17 | | { |
| | 18 | 18 | | TypeName = typeName; |
| | 18 | 19 | | AssemblyName = assemblyName; |
| | 18 | 20 | | IsInterface = isInterface; |
| | 18 | 21 | | IsPartial = isPartial; |
| | 18 | 22 | | Properties = properties; |
| | 18 | 23 | | SourceFilePath = sourceFilePath; |
| | 18 | 24 | | } |
| | | 25 | | |
| | | 26 | | /// <summary>Fully qualified type name of the interface or class.</summary> |
| | 132 | 27 | | public string TypeName { get; } |
| | | 28 | | |
| | 0 | 29 | | public string AssemblyName { get; } |
| | | 30 | | |
| | | 31 | | /// <summary>True if the [Provider] attribute is on an interface.</summary> |
| | 90 | 32 | | public bool IsInterface { get; } |
| | | 33 | | |
| | | 34 | | /// <summary>True if the type is a partial class (required for shorthand mode).</summary> |
| | 12 | 35 | | public bool IsPartial { get; } |
| | | 36 | | |
| | | 37 | | /// <summary>Properties to generate on the provider.</summary> |
| | 42 | 38 | | public IReadOnlyList<ProviderPropertyInfo> Properties { get; } |
| | | 39 | | |
| | 36 | 40 | | public string? SourceFilePath { get; } |
| | | 41 | | |
| | | 42 | | /// <summary>Gets simple type name without namespace (e.g., "IOrderProvider" from "global::TestApp.IOrderProvider"). |
| | | 43 | | public string SimpleTypeName |
| | | 44 | | { |
| | | 45 | | get |
| | | 46 | | { |
| | 72 | 47 | | var name = TypeName; |
| | 72 | 48 | | var lastDot = name.LastIndexOf('.'); |
| | 72 | 49 | | return lastDot >= 0 ? name.Substring(lastDot + 1) : name; |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | |
| | | 53 | | /// <summary>Gets the implementation class name (removes leading "I" from interface name if present).</summary> |
| | | 54 | | public string ImplementationTypeName |
| | | 55 | | { |
| | | 56 | | get |
| | | 57 | | { |
| | 24 | 58 | | var simple = SimpleTypeName; |
| | 24 | 59 | | if (IsInterface && simple.StartsWith("I") && simple.Length > 1 && char.IsUpper(simple[1])) |
| | | 60 | | { |
| | 24 | 61 | | return simple.Substring(1); |
| | | 62 | | } |
| | 0 | 63 | | return simple; |
| | | 64 | | } |
| | | 65 | | } |
| | | 66 | | |
| | | 67 | | /// <summary>Gets the interface name (adds leading "I" to class name if needed).</summary> |
| | | 68 | | public string InterfaceTypeName |
| | | 69 | | { |
| | | 70 | | get |
| | | 71 | | { |
| | 12 | 72 | | var simple = SimpleTypeName; |
| | | 73 | | // For non-interfaces, add "I" prefix unless the name already follows interface naming convention (IXxx) |
| | 12 | 74 | | if (!IsInterface) |
| | | 75 | | { |
| | | 76 | | // Only treat as already having interface prefix if it starts with "I" followed by uppercase letter |
| | 12 | 77 | | if (simple.Length > 1 && simple[0] == 'I' && char.IsUpper(simple[1])) |
| | | 78 | | { |
| | 0 | 79 | | return simple; |
| | | 80 | | } |
| | 12 | 81 | | return "I" + simple; |
| | | 82 | | } |
| | 0 | 83 | | return simple; |
| | | 84 | | } |
| | | 85 | | } |
| | | 86 | | } |