using Avalonia.Collections; using CommunityToolkit.Mvvm.ComponentModel; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; using System.Collections.Generic; using System.Linq; namespace Needlework.Net.Desktop.ViewModels { public class PropertyClassViewModel : ObservableObject { public string Id { get; } public IAvaloniaReadOnlyList PropertyFields { get; } = new AvaloniaList(); public IAvaloniaReadOnlyList PropertyEnums { get; } = new AvaloniaList(); public PropertyClassViewModel(string id, IDictionary properties, IList enumValue) { AvaloniaList propertyFields = []; AvaloniaList propertyEnums = []; foreach ((var propertyName, var propertySchema) in properties) { var type = OperationViewModel.GetSchemaType(propertySchema); var field = new PropertyFieldViewModel(propertyName, type); propertyFields.Add(field); } if (enumValue != null && enumValue.Any()) { var propertyEnum = new PropertyEnumViewModel(enumValue); propertyEnums.Add(propertyEnum); } PropertyFields = propertyFields; PropertyEnums = propertyEnums; Id = id; } } }