using System.Collections.ObjectModel; using System.Linq; using CommunityToolkit.Mvvm.ComponentModel; using GazpromApp.Models; namespace GazpromApp.ViewModels; public partial class PropertyViewModel : ViewModelBase { private Property Property { get; } [ObservableProperty] private string _name; [ObservableProperty] private string _value; public ObservableCollection Properties { get; set; } // Visual and other properties public PropertyViewModel? Parent { get; init; } [ObservableProperty] private bool _isEditing; public Property GetProperty(Property? parent = null) { Property.Name = Name; Property.Value = Value; Property.Parent = parent; Property.Properties = Properties.Select(e => e.GetProperty(Property)).ToList(); return Property; } public PropertyViewModel() { Name = "Имя свойства"; Value = "Значение свойства"; Properties = []; Parent = null; Property = new Property(); } public PropertyViewModel(Property property, PropertyViewModel? parent = null) { Name = property.Name; Value = property.Value; Properties = new ObservableCollection( property.Properties.Select(e => new PropertyViewModel(e, this))); Parent = property.Parent is null ? null : parent; Property = property; } public PropertyViewModel(PropertyViewModel property) { Name = "Имя свойства"; Value = "Значение свойства"; Properties = []; Parent = property; Property = new Property(); } }