using CommunityToolkit.Mvvm.ComponentModel; using System.Text.Json.Serialization; namespace EscribePassword { public partial class Passwords : ObservableObject { [ObservableProperty] private string usuario; [ObservableProperty] private string password; [ObservableProperty] private string categoria; public static List ConvertArrayToPasswordsList(string[,] tableArray) { var passwordsList = new List(); for (int i = 0; i < tableArray.GetLength(0); i++) { var passwords = new Passwords(); if (tableArray.GetLength(1) >= 1) passwords.Categoria = tableArray[i, 0]; if (tableArray.GetLength(1) >= 2) passwords.Usuario = tableArray[i, 1]; if (tableArray.GetLength(1) >= 3) passwords.Password = tableArray[i, 2]; passwordsList.Add(passwords); } return passwordsList; } public static string[,] ConvertPasswordsListToArray(List passwordsList) { if (passwordsList == null || passwordsList.Count == 0) return new string[0, 0]; int rows = passwordsList.Count; int columns = 3; // Asumimos que siempre hay tres columnas: Usuario, Password, Categoria string[,] tableArray = new string[rows + 1, columns]; // Fill header tableArray[0, 0] = "Class"; tableArray[0, 1] = "User"; tableArray[0, 2] = "Password"; // Fill data for (int i = 0; i < rows; i++) { tableArray[i + 1, 0] = passwordsList[i].Categoria; tableArray[i + 1, 1] = passwordsList[i].Usuario; tableArray[i + 1, 2] = passwordsList[i].Password; } return tableArray; } } }