microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Apps/Plugins/PluginService.cs
29lines · modecode
| 1 | using System.Reflection; |
| 2 | |
| 3 | namespace Microsoft.Teams.Apps.Plugins; |
| 4 | |
| 5 | internal static class PluginService |
| 6 | { |
| 7 | public static PluginAttribute GetAttribute(IPlugin plugin) |
| 8 | { |
| 9 | var assembly = Assembly.GetAssembly(plugin.GetType()); |
| 10 | var attribute = (PluginAttribute?)Attribute.GetCustomAttribute(plugin.GetType(), typeof(PluginAttribute)); |
| 11 | |
| 12 | if (attribute is null) |
| 13 | { |
| 14 | throw new InvalidOperationException($"type '{plugin.GetType().Name}' is not a valid plugin"); |
| 15 | } |
| 16 | |
| 17 | if (attribute.Name == string.Empty) |
| 18 | { |
| 19 | attribute.Name = assembly?.GetName().Name ?? throw new InvalidOperationException("plugin is missing a name"); |
| 20 | } |
| 21 | |
| 22 | if (attribute.Version == string.Empty) |
| 23 | { |
| 24 | attribute.Version = assembly?.GetName()?.Version?.ToString() ?? "0.0.0"; |
| 25 | } |
| 26 | |
| 27 | return attribute; |
| 28 | } |
| 29 | } |