카드 작성을 위한 .NET SDK

시작 페이지에서 설명한 대로 적응형 카드는 JSON 개체 모델입니다. .NET 라이브러리를 사용하면 JSON 작업을 훨씬 쉽게 할 수 있습니다.

NuGet 설치

NuGet 패키지는 AdaptiveCards .NET에서 적응형 카드 작업을 위한 형식을 제공합니다.

Nuget install

Install-Package AdaptiveCards

예: AdaptiveCard 만들기 및 JSON으로 직렬화

이 예제에서는 표준 C# 개체를 사용하여 적응형 카드를 빌드한 다음 와이어를 통해 전송하기 위해 JSON으로 직렬화하는 방법을 보여 줍니다.

using AdaptiveCards;
// ...

AdaptiveCard card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));

card.Body.Add(new AdaptiveTextBlock() 
{
    Text = "Hello",
    Size = AdaptiveTextSize.ExtraLarge
});

card.Body.Add(new AdaptiveImage() 
{
    Url = new Uri("http://adaptivecards.io/content/cats/1.png")
});

// serialize the card to JSON
string json = card.ToJson();

예: JSON에서 AdaptiveCard 구문 분석

이 예제에서는 JSON 페이로드를 적응형 카드로 구문 분석하는 방법을 보여 줍니다. 이렇게 하면 렌더러 SDK를 사용하여 개체 모델을 조작하거나 앱 내에서 적응형 카드를 쉽게 렌더링할 수 있습니다.

try
{
    // Get a JSON-serialized payload
    // Your app will probably get cards from somewhere else :)
    var client = new HttpClient();
    var response = await client.GetAsync("http://adaptivecards.io/payloads/ActivityUpdate.json");
    var json = await response.Content.ReadAsStringAsync();

    // Parse the JSON 
    AdaptiveCardParseResult result = AdaptiveCard.FromJson(json);

    // Get card from result
    AdaptiveCard card = result.Card;

    // Optional: check for any parse warnings
    // This includes things like unknown element "type"
    // or unknown properties on element
    IList<AdaptiveWarning> warnings = result.Warnings;
}
catch(AdaptiveSerializationException ex)
{
    // Failed to deserialize card 
    // This occurs from malformed JSON
    // or schema violations like required properties missing 
}