From 295edcaaa90c2e12b6f6a7b907a853ae9e5c3885 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Thu, 30 Nov 2023 00:55:32 +0400 Subject: [PATCH] Change fields to properties --- .../Components/AbazovTreeView.cs | 18 +++++++++--------- .../LogicalComponents/ExcelDiagramComponent.cs | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/AbazovApp/AbazovViewComponents/Components/AbazovTreeView.cs b/AbazovApp/AbazovViewComponents/Components/AbazovTreeView.cs index 8a68255..8c0c25f 100644 --- a/AbazovApp/AbazovViewComponents/Components/AbazovTreeView.cs +++ b/AbazovApp/AbazovViewComponents/Components/AbazovTreeView.cs @@ -38,16 +38,16 @@ namespace AbazovViewComponents.Components TreeNode? node = treeView.SelectedNode; var type = typeof(T); - var fields = type.GetFields(); + var properties = type.GetProperties(); var item = Activator.CreateInstance(type); while (node != null) { - var field = fields.FirstOrDefault(x => x.Name == node.Name); - if (field != null) + var property = properties.FirstOrDefault(x => x.Name == node.Name); + if (property != null) { - field.SetValue(item, node.Text); + property.SetValue(item, node.Text); } node = node.Parent; } @@ -63,23 +63,23 @@ namespace AbazovViewComponents.Components public void addItems(List items) { var type = typeof(T); - var fields = type.GetFields(); + var properties = type.GetProperties(); foreach (T item in items) { TreeNodeCollection nodes = treeView.Nodes; for (int i = 0; i < hierarchy.Count; i++) { - var field = fields.FirstOrDefault(x => x.Name.Equals(hierarchy[i].Item1)); - if (field is not null) + var property = properties.FirstOrDefault(x => x.Name.Equals(hierarchy[i].Item1)); + if (property is not null) { - var node = nodes.Find(field.Name, false).FirstOrDefault(x => x.Text == field.GetValue(item).ToString()); + var node = nodes.Find(property.Name, false).FirstOrDefault(x => x.Text == property.GetValue(item).ToString()); if (node is not null && !hierarchy[i].Item2) { nodes = node.Nodes; } else { - TreeNode newNode = nodes.Add(field.Name, field.GetValue(item).ToString()); + TreeNode newNode = nodes.Add(property.Name, property.GetValue(item).ToString()); nodes = newNode.Nodes; } } diff --git a/AbazovApp/AbazovViewComponents/LogicalComponents/ExcelDiagramComponent.cs b/AbazovApp/AbazovViewComponents/LogicalComponents/ExcelDiagramComponent.cs index 79595ac..334cb6d 100644 --- a/AbazovApp/AbazovViewComponents/LogicalComponents/ExcelDiagramComponent.cs +++ b/AbazovApp/AbazovViewComponents/LogicalComponents/ExcelDiagramComponent.cs @@ -32,8 +32,8 @@ namespace AbazovViewComponents.LogicalComponents { Worksheet worksheet = (Worksheet)workbook.Worksheets.get_Item(1); - FieldInfo? seriesName = typeof(T).GetField(seriesNameField); - FieldInfo? value = typeof(T).GetField(valueField); + PropertyInfo? seriesName = typeof(T).GetProperty(seriesNameField); + PropertyInfo? value = typeof(T).GetProperty(valueField); if (seriesName == null || value == null) throw new ArgumentException("Переданного поля не существует"); int columnCount = 2; foreach(var item in data)