edit lab 1 and accept
This commit is contained in:
parent
5489c642f0
commit
2a0c55f7b5
@ -71,12 +71,14 @@ namespace ComponentsLibrary
|
||||
|
||||
}
|
||||
// Публичный параметризованный метод для получения объекта из выбранной строки
|
||||
public T? GetSelectedItem<T>() where T : new()
|
||||
public T GetSelectedItem<T>() where T : new()
|
||||
{
|
||||
var selectedItem = listBox.SelectedItem;
|
||||
if (selectedItem != null)
|
||||
if (selectedItem == null)
|
||||
{
|
||||
string selectedString = selectedItem.ToString(); // Строка из ListBox
|
||||
throw new Exception();
|
||||
}
|
||||
string selectedString = selectedItem.ToString();
|
||||
T obj = new T();
|
||||
|
||||
PropertyInfo[] properties = typeof(T).GetProperties();
|
||||
@ -100,8 +102,6 @@ namespace ComponentsLibrary
|
||||
Regex regex = new Regex(pattern);
|
||||
Match match = regex.Match(selectedString);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
for (int i = 0; i < properties.Length; i++)
|
||||
{
|
||||
string value = match.Groups[i + 1].Value;
|
||||
@ -109,10 +109,7 @@ namespace ComponentsLibrary
|
||||
properties[i].SetValue(obj, convertedValue);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user