I'd like to implement a public getter which will get values of all string properties in current class instance and return it as concatinated string.
public class BaseViewModel
{
public string AllProperties => GetType().GetProperties().Aggregate(string.Empty, (current, prop) => prop.PropertyType == typeof(string) ? current + (string)prop.GetValue(this, null) : current);
}
public class ChildViewModel : BaseViewModel
{
public string prop1 { get; set; }
public string prop2 { get; set; }
}
When I run this I get StackOverflowException..
Aucun commentaire:
Enregistrer un commentaire