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