первичный класс < /p>
Код: Выделить всё
public class PrimaryClass
{
public string PcItemOne { get; set; } = "PC1";
public string PcItemTwo { get; set; } = "PC2";
public string PcItemThree { get; set; } = "PC3";
public SecondaryClass SecondaryClass { get; set; } = new SecondaryClass();
}
< /code>
Вторичный класс < /p>
public class SecondaryClass
{
public string ScItemOne { get; set; } = "SC1";
public string ScItemTwo { get; set; } = "SC2";
public string ScItemThree { get; set; } = "SC3";
}
< /code>
Общий метод. Я хочу передать в первичный класс в этот метод и установить значения внутри вторичного класса. < /P>
public void CallClassProperty(T cls) where T : class
{
Console.WriteLine(typeof(T).Name);
// Something like this but I need to get the reference to Secondary class.
cls.SecondaryClass.ScItemTwo = "my new value";
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... in-c-sharp