Sto scrivendo un'applicazione Windows 8 in C# e XAML. Ho una classe con molte proprietà dello stesso tipo che sono impostate nel costruttore nello stesso modo. Invece di scrivere e assegnare per ciascuna delle proprietà a mano, voglio ottenere un elenco di tutte le proprietà di un determinato tipo sulla mia classe e impostarle tutte in un foreach.Come ottenere le proprietà di una classe in WinRT
In .NET "normale" Vorrei scrivere questo
var properties = this.GetType().GetProperties();
foreach (var property in properties)
{
if (property.PropertyType == typeof(Tuple<string,string>))
property.SetValue(this, j.GetTuple(property.Name));
}
dove j
è un parametro del mio costruttore. In WinRT il GetProperties()
non esiste. Intellisense per this.GetType().
non mostra nulla di utile che potrei usare.
http://msdn.microsoft.com/en-us/library/windows/apps/br230302.aspx#reflection –