Через рефлексию присвоить одинаковое значение всем свойствам класса - C#
Формулировка задачи:
есть, например, класс
Как при создании экземпляра класса заполнить все свойства значением " " .
Не все свойства в процессе работы программы будут иметь значения. Поэтому хочу в них убрать значение null
class Item
{
public string FIO {get;set;}
public string Telefon { get; set; }
public string Object { get; set; }
public string DateStart { get; set; }
public string DataFinish { get; set; }
public string Adress { get; set; }
public string Koordinaty { get; set; }
public string PointCount { get; set; }
public string Zarplata { get; set; }
public string Bonus { get; set; }
public string SmetaClient { get; set; }
public string Kategory { get; set; }
public string TextNote { get; set; }
public string FaseCount { get; set; }
public string Power { get; set; }
public string Generator { get; set; }
public string Stabilizer { get; set; }
public string AVR { get; set; }
public string Satellite { get; set; }
public string Text { get; set; }
public string Folder { get; set; }
}Item item = new Item();
Решение задачи: «Через рефлексию присвоить одинаковое значение всем свойствам класса»
textual
Листинг программы
var stringValues = string.Join(",", obj.GetType().GetProperties()
.Where(p => p.PropertyType == typeof(string))
.Select(p => p.GetValue(obj)));