| | | 1 | | namespace NexusLabs.Needlr.Generators.Models; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Information about a factory-generated type (from [GenerateFactory]). |
| | | 5 | | /// </summary> |
| | | 6 | | internal readonly struct DiscoveredFactory |
| | | 7 | | { |
| | | 8 | | public DiscoveredFactory( |
| | | 9 | | string typeName, |
| | | 10 | | string[] interfaceNames, |
| | | 11 | | string assemblyName, |
| | | 12 | | int generationMode, |
| | | 13 | | FactoryDiscoveryHelper.FactoryConstructorInfo[] constructors, |
| | | 14 | | string? returnTypeName = null, |
| | | 15 | | string? sourceFilePath = null) |
| | | 16 | | { |
| | 24 | 17 | | TypeName = typeName; |
| | 24 | 18 | | InterfaceNames = interfaceNames; |
| | 24 | 19 | | AssemblyName = assemblyName; |
| | 24 | 20 | | GenerationMode = generationMode; |
| | 24 | 21 | | Constructors = constructors; |
| | 24 | 22 | | ReturnTypeOverride = returnTypeName; |
| | 24 | 23 | | SourceFilePath = sourceFilePath; |
| | 24 | 24 | | } |
| | | 25 | | |
| | 350 | 26 | | public string TypeName { get; } |
| | 0 | 27 | | public string[] InterfaceNames { get; } |
| | 0 | 28 | | public string AssemblyName { get; } |
| | | 29 | | /// <summary>Mode flags: 1=Func, 2=Interface, 3=All</summary> |
| | 72 | 30 | | public int GenerationMode { get; } |
| | 92 | 31 | | public FactoryDiscoveryHelper.FactoryConstructorInfo[] Constructors { get; } |
| | | 32 | | /// <summary> |
| | | 33 | | /// If set, the factory Create() and Func return this type instead of the concrete type. |
| | | 34 | | /// Used when [GenerateFactory<T>] is applied. |
| | | 35 | | /// </summary> |
| | 78 | 36 | | public string? ReturnTypeOverride { get; } |
| | 0 | 37 | | public string? SourceFilePath { get; } |
| | | 38 | | |
| | 24 | 39 | | public bool GenerateFunc => (GenerationMode & 1) != 0; |
| | 48 | 40 | | public bool GenerateInterface => (GenerationMode & 2) != 0; |
| | | 41 | | |
| | | 42 | | /// <summary>Gets the type that factory Create() and Func should return.</summary> |
| | 78 | 43 | | public string ReturnTypeName => ReturnTypeOverride ?? TypeName; |
| | | 44 | | |
| | | 45 | | /// <summary>Gets just the type name without namespace (e.g., "MyService" from "global::TestApp.MyService").</summar |
| | | 46 | | public string SimpleTypeName |
| | | 47 | | { |
| | | 48 | | get |
| | | 49 | | { |
| | 168 | 50 | | var parts = TypeName.Split('.'); |
| | 168 | 51 | | return parts[parts.Length - 1]; |
| | | 52 | | } |
| | | 53 | | } |
| | | 54 | | } |