Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,39 @@ internal static string ConvertToJson(object obj)
/// </example>
/// <param name="jsonTemplate">string in json or seriazable object</param>
public AdaptiveCardTemplate(string jsonTemplate)
: this(jsonTemplate, validate: false) { }

/// <summary>
/// <para>Creates an instance of AdaptiveCardTemplate</para>
/// </summary>
/// <remarks>
/// <para>Once created, it will contain a parsed tree based on jsonTemplate</para>
/// <para>Data is bound by calling <c>Expand</c> on the object</para>
/// <para>The intance can be rebound with different data by calling <c>Expand</c></para>
/// <see cref="Expand(EvaluationContext, Func{string, object})"/>
/// </remarks>
/// <example>
/// <code>
/// var jsonTemplate = "
/// {
/// "type": "AdaptiveCard",
/// "version": "1.0",
/// "body": [
/// {
/// "type": "TextBlock",
/// "text": "Hello ${person.firstName}"
/// }
/// ]
///}"
/// var template = new AdaptiveCardTemplate(jsonTemplate);
/// </code>
/// </example>
/// <param name="jsonTemplate">string in json or seriazable object</param>
public AdaptiveCardTemplate(string jsonTemplate, bool validate)
{
if (validate && string.IsNullOrWhiteSpace(jsonTemplate))
throw new ArgumentException("The value cannot be an empty string or composed entirely of whitespace.", nameof(jsonTemplate));

if (jsonTemplate != null)
{
jsonTemplateString = jsonTemplate;
Expand All @@ -84,6 +116,11 @@ public AdaptiveCardTemplate(string jsonTemplate)
BuildParseTree = true
};

if (validate)
{
parser.ErrorHandler = new BailErrorStrategy();
}

parseTree = parser.json();
}
}
Expand Down