I have to set the value of a property custom class with reflection. This is an example of what I have to get.
class Phone
{
public detailsTelephone DetailsTelephone { get; set; } = new detailsTelephone();
}
class detailsTelephone
{
public PhoneName PHONENAME { get; set; } = new PhoneName();
public PhoneCover PHONECOVER { get; set; } = new PhoneCover();
}
class PhoneName
{
public string LenghtName { get; set; } = string.Empty;
}
class PhoneCover
{
public string ColorCover { get; set; } = string.Empty;
}
class Program
{
static List<Phone> PhoneList = new List<Phone>();
static void Main(string[] args)
{
PhoneList.Add(new Phone());
detailsTelephone p = PhoneList.Last().DetailsTelephone;
var property = typeof(detailsTelephone).GetProperty("PHONENAME");
property.SetValue(p.PHONENAME.LenghtName, "1000", null);
Console.WriteLine(PhoneList.Last().DetailsTelephone.PHONENAME.LenghtName);
Console.ReadLine();
}
}
I updated the post with the real structure I have in the project. The problem is that I have to find the first property by name (PHONENAME) and then set the PHONENAME.LenghtName to 1000 property.
Thanks in advance.