microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next/core

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

32lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using System.Reflection;
5
6namespace Microsoft.Teams.Apps.Plugins;
7
8internal static class PluginService
9{
10 public static PluginAttribute GetAttribute(IPlugin plugin)
11 {
12 var assembly = Assembly.GetAssembly(plugin.GetType());
13 var attribute = (PluginAttribute?)Attribute.GetCustomAttribute(plugin.GetType(), typeof(PluginAttribute));
14
15 if (attribute is null)
16 {
17 throw new InvalidOperationException($"type '{plugin.GetType().Name}' is not a valid plugin");
18 }
19
20 if (attribute.Name == string.Empty)
21 {
22 attribute.Name = assembly?.GetName().Name ?? throw new InvalidOperationException("plugin is missing a name");
23 }
24
25 if (attribute.Version == string.Empty)
26 {
27 attribute.Version = assembly?.GetName()?.Version?.ToString() ?? "0.0.0";
28 }
29
30 return attribute;
31 }
32}