File: ConfigModel\CustomOperationModel.cs
Web Access
Project: src\sdk\src\TemplateEngine\Microsoft.TemplateEngine.Orchestrator.RunnableProjects\Microsoft.TemplateEngine.Orchestrator.RunnableProjects.csproj (Microsoft.TemplateEngine.Orchestrator.RunnableProjects)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Text.Json.Nodes;

namespace Microsoft.TemplateEngine.Orchestrator.RunnableProjects.ConfigModel
{
    /// <summary>
    /// Defines the operation configuration.
    /// </summary>
    public sealed class CustomOperationModel : ConditionedConfigurationElement
    {
        internal CustomOperationModel() { }

        /// <summary>
        /// Gets the operation type.
        /// </summary>
        public string? Type { get; internal init; }

        /// <summary>
        /// Gets the operation raw configuration in JSON format.
        /// </summary>
        public string? Configuration { get; internal init; }

        internal static CustomOperationModel FromJObject(JsonObject jObject)
        {
            CustomOperationModel model = new CustomOperationModel
            {
                Type = jObject.ToString(nameof(Type)),
                Condition = jObject.ToString(nameof(Condition)),
                Configuration = jObject.Get<JsonObject>(nameof(Configuration))?.ToJsonString(),
            };

            return model;
        }
    }
}