Files
agent-framework/dotnet/samples/M365Agent/Agents/AdaptiveCardAIContent.cs
westey e413c5a285 .NET: Add M365 Agent SDK Hosting sample (#2221)
* Add M365 Agent SDK interop sample

* Update dotnet/samples/M365Agent/README.md

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Address some comments.

* Update dotnet/samples/M365Agent/Agents/WeatherForecastAgent.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dotnet/samples/M365Agent/Agents/WeatherForecastAgentResponse.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update dotnet/samples/M365Agent/Agents/WeatherForecastAgentResponse.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Address PR comments

* Refactor code to simplify.

* Fix broken link.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-11-17 19:19:52 +00:00

37 lines
1.3 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System.Text.Json.Serialization;
using AdaptiveCards;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
namespace M365Agent.Agents;
/// <summary>
/// An <see cref="AIContent"/> type allows an <see cref="AIAgent"/> to return adaptive cards as part of its response messages.
/// </summary>
internal sealed class AdaptiveCardAIContent : AIContent
{
public AdaptiveCardAIContent(AdaptiveCard adaptiveCard)
{
this.AdaptiveCard = adaptiveCard ?? throw new ArgumentNullException(nameof(adaptiveCard));
}
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
[JsonConstructor]
public AdaptiveCardAIContent(string adaptiveCardJson)
{
this.AdaptiveCardJson = adaptiveCardJson;
}
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
[JsonIgnore]
public AdaptiveCard AdaptiveCard { get; private set; }
public string AdaptiveCardJson
{
get => this.AdaptiveCard.ToJson();
set => this.AdaptiveCard = AdaptiveCard.FromJson(value).Card;
}
}