Skip to content

Instantly share code, notes, and snippets.

@programmation
Created February 11, 2016 21:50
Show Gist options
  • Save programmation/6740d318435d70915872 to your computer and use it in GitHub Desktop.
Save programmation/6740d318435d70915872 to your computer and use it in GitHub Desktop.
GetProperty equivalent code in PCL
// https://forums.xamarin.com/discussion/comment/180081/#Comment_180081
// Platform project
{
var type = item.GetType();
var prop = type.GetProperty(picker.DisplayMember);
picker.Items.Add(prop.GetValue(item).ToString());
}
// PCL
{
var prop = item.GetType().GetRuntimeProperties().FirstOrDefault(p => string.Equals(p.Name, picker.DisplayMember, StringComparison.OrdinalIgnoreCase));
if (prop != null)
{
picker.Items.Add(prop.GetValue(item).ToString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment