System.Windows.Forms.Util.GetPropertyStringValue C# (CSharp) Method

GetPropertyStringValue() public static method

public static GetPropertyStringValue ( object inObject, string propertyName ) : string
inObject object
propertyName string
return string
		public static string GetPropertyStringValue (object inObject, string propertyName)
		{
			PropertyInfo[] props = inObject.GetType ().GetProperties ();
			PropertyInfo prop = props.Select (p => p).Where (p => p.Name == propertyName).FirstOrDefault ();
			if (prop != null)
				return prop.GetValue (inObject, null).ToString ();
			return "";
		}

Usage Example

 public override NSObject ObjectValueForItem(NSComboBox comboBox, int index)
 {
     if (cbox == null)
     {
         return(null);
     }
     if (string.IsNullOrEmpty(cbox.DisplayMember))
     {
         returnString = new NSString(cbox.Items[index].ToString());
     }
     else
     {
         returnString = new NSString(Util.GetPropertyStringValue(cbox.Items[index], cbox.DisplayMember));
     }
     return(returnString);
 }
All Usage Examples Of System.Windows.Forms.Util::GetPropertyStringValue