public static string WriteTfLine()

in Webapp/SDAF/Controllers/Helper.cs [117:185]


        public static string WriteTfLine<T>(PropertyInfo property, T model)
        {
            StringBuilder str = new();
            var value = property.GetValue(model);
            if (property.PropertyType.GetElementType() == typeof(Tag))
            {
                if (value == null) return "#" + property.Name + " = {}";
                str.AppendLine(property.Name + " = {");
                foreach (Tag t in (Tag[])value)
                {
                    if (t.Key != null && t.Key.Length > 0)
                    {
                        str.AppendLine($"  \"{t.Key}\" = \"{t.Value}\",");
                    }
                }
                str.Append("}");
            }
            else if (property.PropertyType.IsArray)
            {
                if (value == null) return "#" + property.Name + " = []";
                str.Append(property.Name + " = [");
                foreach (var val in (string[])value)
                {
                    str.Append($"\"{val}\", ");
                }
                str.Remove(str.Length - 2, 2);
                str.Append("]");
            }
            else if (property.PropertyType == typeof(Image))
            {
                if (value == null) return "#" + property.Name + " = {}";
                Image img = (Image)value;
                if (img.IsInitialized)
                {
                    str.AppendLine(property.Name + " = {");
                    str.AppendLine("  os_type = " + $"\"{img.os_type}\",");
                    str.AppendLine("  source_image_id = " + $"\"{img.source_image_id}\",");
                    str.AppendLine("  publisher = " + $"\"{img.publisher}\",");
                    str.AppendLine("  offer = " + $"\"{img.offer}\",");
                    str.AppendLine("  sku = " + $"\"{img.sku}\",");
                    str.AppendLine("  version = " + $"\"{img.version}\",");
                    str.AppendLine("  type = " + $"\"{img.type}\"");
                    str.Append("}");
                }
                else
                {
                    return "#" + property.Name + " = {}";
                }
            }
            else if (property.PropertyType == typeof(bool?))
            {
                if (value == null) return "#" + property.Name + " = false";
                bool b = (bool)value;
                str.Append(property.Name + " = " + b.ToString().ToLower());
            }
            else if (property.PropertyType == typeof(int?))
            {
                if (value == null) return "#" + property.Name + " = 0";
                int i = (int)value;
                str.Append(property.Name + " = " + i);
            }
            else
            {
                if (value == null) return "#" + property.Name + " = \"\"";
                str.Append(property.Name + " = " + $"\"{value}\"");
            }

            return str.ToString();
        }