@layout PageLayout @page "/sandbox" @inject IJSRuntime JS Sandbox
Generic Page of Testing In Progress code
@code { readonly List entities = EntityModel.GetList(); List infos = new(); string infoText = ""; string weaponText = ""; readonly List changes = new(); readonly List patches = new(); private async Task DownloadFile(Type type) { var fileName = $"{type.ToString().Split(".").Last()}s.csv"; var objectData = type == typeof(PatchModel) ? new List(patches) : type == typeof(ChangeModel) ? new List(changes) : new List(); await JS.InvokeVoidAsync("download", fileName, Generate(type, objectData)); } void GenerateEntityModels() { var properties = typeof(EntityInfoModel).GetProperties(); infoText += "Id,Name,Descriptive,Description,Notes\n"; var id = 1; foreach (var entity in entities) { infoText += $"{id++},{entity.Info().Name},{entity.Info().Descriptive},{entity.Info().Description},{entity.Info().Notes}\n"; } } string Generate(Type type, List dataList) { var properties = type.GetProperties(); var generatedText = ""; for (var index = 0; index < properties.Count(); index++) { var property = properties[index]; if (property.GetAccessors().First().IsVirtual) { continue; } var attributes = property.GetCustomAttributes().OfType(); if (attributes.Count() > 0) { continue; } generatedText += property.Name; if (index != properties.Count() - 1) { generatedText += ","; } } generatedText = generatedText.Trim(); if (generatedText.EndsWith(",")) { generatedText = generatedText.Remove(generatedText.Length - 1); } generatedText += "\n"; foreach (var data in dataList) { for (var index = 0; index < properties.Count(); index++) { var property = properties[index]; if (property.GetAccessors().First().IsVirtual) { continue; } var attributes = property.GetCustomAttributes().OfType(); if (attributes.Count() > 0) { continue; } if (property.GetValue(data) != null) { generatedText += "\"" + property.GetValue(data).ToString().Replace("\"", "\"\"") + "\""; if (index != properties.Count() - 1) { generatedText += ","; } } else { generatedText += "\"" + " " + "\""; if (index != properties.Count() - 1) { generatedText += ","; } } } generatedText = generatedText.Trim(); if (generatedText.EndsWith(",")) { generatedText = generatedText.Remove(generatedText.Length - 1); } generatedText += "\n"; } return generatedText; } void GenerateWeapons() { var properties = typeof(EntityWeaponModel).GetProperties(); for (var index = 0; index < properties.Count(); index++) { var property = properties[index]; if (property.GetAccessors().First().IsVirtual) { continue; } var attributes = property.GetCustomAttributes().OfType (); if (attributes.Count() > 0) { continue; } weaponText += property.Name; if (index != properties.Count() - 1) { weaponText += ","; } } weaponText += "\n"; foreach (var entity in entities) { foreach (var weapon in entity.Weapons()) { for (var index = 0; index < properties.Count(); index++) { var property = properties[index]; if (property.GetAccessors().First().IsVirtual) { continue; } var attributes = property.GetCustomAttributes().OfType (); if (attributes.Count() > 0) { continue; } weaponText += property.GetValue(weapon); if (index != properties.Count() - 1) { weaponText += ","; } } weaponText += "\n"; } } } void GenerateExample() { var properties = typeof(EntityInfoModel).GetProperties(); for (var index = 0; index < properties.Count(); index++) { var property = properties[index]; infoText += property.Name; if (index != properties.Count() - 1) { infoText += ","; } } infoText += "\n"; foreach (var entity in entities) { if (entity.Info() != null) { for (var index = 0; index < properties.Count(); index++) { var property = properties[index]; infoText += property.GetValue(entity.Info()); if (index != properties.Count() - 1) { infoText += ","; } } infoText += "\n"; } } } }