| | | 1 | | using Microsoft.CodeAnalysis; |
| | | 2 | | |
| | | 3 | | namespace NexusLabs.Needlr.Generators; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Helper for discovering plugin order attributes from Roslyn symbols. |
| | | 7 | | /// </summary> |
| | | 8 | | internal static class PluginOrderHelper |
| | | 9 | | { |
| | | 10 | | private const string PluginOrderAttributeName = "PluginOrderAttribute"; |
| | | 11 | | private const string PluginOrderAttributeFullName = "NexusLabs.Needlr.PluginOrderAttribute"; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Gets the execution order for a plugin type from the [PluginOrder] attribute. |
| | | 15 | | /// </summary> |
| | | 16 | | /// <param name="typeSymbol">The type symbol to check.</param> |
| | | 17 | | /// <returns>The order value from [PluginOrder], or 0 if not specified.</returns> |
| | | 18 | | public static int GetPluginOrder(INamedTypeSymbol typeSymbol) |
| | | 19 | | { |
| | 2870 | 20 | | foreach (var attribute in typeSymbol.GetAttributes()) |
| | | 21 | | { |
| | 56 | 22 | | var attributeClass = attribute.AttributeClass; |
| | 56 | 23 | | if (attributeClass == null) |
| | | 24 | | continue; |
| | | 25 | | |
| | 56 | 26 | | var name = attributeClass.Name; |
| | 56 | 27 | | var fullName = attributeClass.ToDisplayString(); |
| | | 28 | | |
| | 56 | 29 | | if (name == PluginOrderAttributeName || fullName == PluginOrderAttributeFullName) |
| | | 30 | | { |
| | | 31 | | // The attribute has a single constructor parameter: int order |
| | 0 | 32 | | if (attribute.ConstructorArguments.Length > 0 && |
| | 0 | 33 | | attribute.ConstructorArguments[0].Value is int order) |
| | | 34 | | { |
| | 0 | 35 | | return order; |
| | | 36 | | } |
| | | 37 | | } |
| | | 38 | | } |
| | | 39 | | |
| | 1379 | 40 | | return 0; // Default order |
| | | 41 | | } |
| | | 42 | | } |