@@ -7,7 +7,7 @@ public static class PluginReflector
77{
88 private const string PluginSearchPattern = "*.dll" ;
99
10- public static PluginMetadata ? ExtractPluginMetadata ( string pluginDirectory )
10+ public static PluginMetadata ? ExtractPluginMetadata ( string pluginDirectory , bool verbose )
1111 {
1212 var interfaceType = typeof ( IPlugin ) ;
1313 foreach ( var dllPath in Directory . GetFiles ( pluginDirectory , PluginSearchPattern ) )
@@ -20,7 +20,8 @@ public static class PluginReflector
2020 }
2121 catch ( Exception ex )
2222 {
23- Console . Error . WriteLine ( ex . Message ) ;
23+ if ( verbose )
24+ Console . Error . WriteLine ( ex . Message ) ;
2425 }
2526 finally
2627 {
@@ -29,53 +30,6 @@ public static class PluginReflector
2930 }
3031
3132 return null ;
32-
33-
34- //foreach (var dllPath in Directory.GetFiles(pluginDirectory, "*.dll"))
35- //{
36- // try
37- // {
38- // var assembly = Assembly.LoadFrom(dllPath);
39-
40- // foreach (var type in assembly.GetTypes())
41- // {
42- // if (!type.IsClass || type.IsAbstract || type.IsInterface)
43- // continue;
44-
45- // if (!interfaceType.IsAssignableFrom(type))
46- // continue;
47-
48- // var instance = Activator.CreateInstance(type);
49- // if (instance == null)
50- // continue;
51-
52- // var metadata = new PluginMetadata
53- // {
54- // Id = GetPropertyValue<Guid>(type, instance, nameof(PluginMetadata.Id)),
55- // Type = GetPropertyValue<string>(type, instance, nameof(PluginMetadata.Type)),
56- // Version = GetPropertyValue<string>(type, instance, nameof(PluginMetadata.Version)),
57- // CompanyName = GetPropertyValue<string>(type, instance, nameof(PluginMetadata.CompanyName)),
58- // Description = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.Description)),
59- // License = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.License)),
60- // LicenseUrl = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.LicenseUrl)),
61- // Icon = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.Icon)),
62- // ProjectUrl = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.ProjectUrl)),
63- // RepositoryUrl = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.RepositoryUrl)),
64- // Copyright = GetPropertyValue<string?>(type, instance, nameof(PluginMetadata.Copyright)),
65- // Authors = GetPropertyValue<List<string>>(type, instance, nameof(PluginMetadata.Authors)) ?? new(),
66- // Tags = GetPropertyValue<List<string>>(type, instance, nameof(PluginMetadata.Tags)) ?? new()
67- // };
68-
69- // return metadata;
70- // }
71- // }
72- // catch (Exception ex)
73- // {
74- // Console.Error.WriteLine($"Failed to read metadata from {dllPath}: {ex.Message}");
75- // }
76- //}
77-
78- //return null;
7933 }
8034
8135 private static PluginMetadata CreatePluginMetadata ( IPlugin plugin )
@@ -98,15 +52,6 @@ private static PluginMetadata CreatePluginMetadata(IPlugin plugin)
9852 } ;
9953 }
10054
101- private static T ? GetPropertyValue < T > ( Type type , object instance , string propertyName )
102- {
103- var prop = type . GetProperty ( propertyName ) ;
104- if ( prop == null || ! typeof ( T ) . IsAssignableFrom ( prop . PropertyType ) )
105- return default ;
106-
107- return ( T ? ) prop . GetValue ( instance ) ;
108- }
109-
11055 public static string SaveMetadataToFile ( PluginMetadata metadata , string outputDirectory )
11156 {
11257 var json = JsonSerializer . Serialize ( metadata , new JsonSerializerOptions { WriteIndented = true } ) ;
0 commit comments