microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.0.0-preview.5

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Apps/Plugins/PluginService.cs

29lines · modecode

1using System.Reflection;
2
3namespace Microsoft.Teams.Apps.Plugins;
4
5internal 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}