ебать какая правочка
This commit is contained in:
parent
d8ad4d290a
commit
2db862aa64
@ -55,23 +55,42 @@ namespace ComponentProgramming
|
||||
}
|
||||
string row = listBox.SelectedItem!.ToString()!;
|
||||
T obj = new T();
|
||||
StringBuilder sb = new StringBuilder(row);
|
||||
|
||||
List<string> substrings = new List<string>();
|
||||
List<string> props = new List<string>();
|
||||
|
||||
string template = _templateString;
|
||||
|
||||
foreach (var prop in typeof(T).GetProperties())
|
||||
{
|
||||
if (!prop.CanWrite || prop.Name == "Id")
|
||||
props.Add(prop.Name);
|
||||
template = template.Replace(prop.Name, "");
|
||||
}
|
||||
|
||||
substrings.AddRange(template.Split(_startSymbol + _endSymbol));
|
||||
|
||||
int int1 = 0; int int2 = 0;
|
||||
|
||||
foreach (var prop in typeof(T).GetProperties())
|
||||
{
|
||||
for (int i = 0; i <= substrings.Count - 2; i++)
|
||||
{
|
||||
continue;
|
||||
int1 = row.IndexOf(substrings[i]) + substrings[i].Length;
|
||||
int2 = row.IndexOf(substrings[i + 1]);
|
||||
if (substrings[i+1] == "")
|
||||
{
|
||||
int2 = row.Length;
|
||||
}
|
||||
if (props[i] == prop.Name)
|
||||
{
|
||||
var value = row[int1..int2];
|
||||
if (value.Contains(prop.Name))
|
||||
{
|
||||
value = null;
|
||||
}
|
||||
prop.SetValue(obj, Convert.ChangeType(value, prop.PropertyType));
|
||||
}
|
||||
}
|
||||
|
||||
int borderOne = sb.ToString().IndexOf(_startSymbol);
|
||||
if (borderOne == -1) break;
|
||||
|
||||
int borderTwo = sb.ToString().IndexOf(_endSymbol, borderOne + 1);
|
||||
if (borderTwo == -1) break;
|
||||
|
||||
string propValue = sb.ToString(borderOne + 1, borderTwo - borderOne - 1);
|
||||
sb.Remove(0, borderTwo + 1);
|
||||
prop.SetValue(obj, Convert.ChangeType(propValue, prop.PropertyType));
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
@ -89,7 +108,7 @@ namespace ComponentProgramming
|
||||
if(propInfo != null)
|
||||
{
|
||||
object propValue = propInfo.GetValue(dataObj)!;
|
||||
row = row.Replace($"{_startSymbol}{propName}{_endSymbol}", $"{_startSymbol}{propValue.ToString()}{_endSymbol}");
|
||||
row = row.Replace($"{_startSymbol}{propName}{_endSymbol}", $"{propValue.ToString()}");
|
||||
listBox.Items[rowIndex] = row;
|
||||
}
|
||||
}
|
||||
|
@ -25,9 +25,9 @@ namespace Forms
|
||||
}
|
||||
private void FillList()
|
||||
{
|
||||
controlListBox.SetTemplateString("Ïðèâåò [Name] [Surname]", "[", "]");
|
||||
controlListBox.FillProp<Person>(new Person(1, "Ñàøêà", "Èçîòîâ"), 0, "Name");
|
||||
controlListBox.FillProp<Person>(new Person(2, "Ñàøêà", "Èçîòîâ"), 4, "Surname");
|
||||
controlListBox.SetTemplateString("Ïðèâåò [Name] dsfdsfds [Surname]", "[", "]");
|
||||
controlListBox.FillProp<Person>(new Person("Ñàøêasdasà", "Èçîòîâ"), 0, "Name");
|
||||
controlListBox.FillProp<Person>(new Person("Ñàøêà", "Èçîòîâ"), 4, "Surname");
|
||||
}
|
||||
|
||||
private void controlComboBox_ComboBoxChanged(object sender, EventArgs e)
|
||||
|
@ -8,16 +8,14 @@ namespace Forms
|
||||
{
|
||||
public class Person
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Surname { get; set; }
|
||||
|
||||
public Person() { }
|
||||
|
||||
public Person(int id, string name, string surname)
|
||||
public Person(string name, string surname)
|
||||
{
|
||||
Name = name;
|
||||
Id = id;
|
||||
Surname = surname;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user