microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.0.0-preview.13

Branches

Tags

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

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Apps/Annotations/ContextAttribute.cs

36lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using System.Reflection;
5
6using Microsoft.Teams.Api;
7using Microsoft.Teams.Api.Activities;
8using Microsoft.Teams.Api.Auth;
9using Microsoft.Teams.Api.Clients;
10using Microsoft.Teams.Apps.Plugins;
11using Microsoft.Teams.Common.Extensions;
12using Microsoft.Teams.Common.Logging;
13using Microsoft.Teams.Common.Storage;
14
15namespace Microsoft.Teams.Apps.Annotations;
16
17[AttributeUsage(AttributeTargets.Parameter, Inherited = true)]
18public class ContextAttribute : ContextAccessorAttribute
19{
20 public override object? GetValue(IContext<IActivity> context, ParameterInfo parameter)
21 {
22 var type = parameter.ParameterType;
23
24 if (type == typeof(ILogger)) return context.Log;
25 if (type == typeof(IStorage<string, object>)) return context.Storage;
26 if (type == typeof(IStreamer)) return context.Stream;
27 if (type.IsAssignableTo(typeof(IActivity))) return context.Activity.ToType(parameter.ParameterType, null);
28 if (type == typeof(ApiClient)) return context.Api;
29 if (type == typeof(CancellationToken)) return context.CancellationToken;
30 if (type == typeof(ConversationReference)) return context.Ref;
31 if (type == typeof(IContext.Client)) return new IContext.Client(context);
32 if (type == typeof(IContext.Next)) return new IContext.Next(context.Next);
33 if (type == typeof(JsonWebToken)) return context.UserGraphToken;
34 return context;
35 }
36}