Created
February 11, 2016 21:50
-
-
Save programmation/6740d318435d70915872 to your computer and use it in GitHub Desktop.
GetProperty equivalent code in PCL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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