// Converts an instance of PropertyValue to its appropriate display name public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (typeof(string).IsAssignableFrom(targetType)) { PropertyValue propertyValue = value as PropertyValue; if (propertyValue != null) { ModelPropertyEntryBase propertyEntry = propertyValue.ParentProperty as ModelPropertyEntryBase; // Figure out the value type name string valueTypeName = string.Empty; if (propertyEntry != null) { valueTypeName = propertyEntry.CommonValueType == null ? string.Empty : propertyEntry.CommonValueType.Name; } else { Debug.Fail("PropertyValueToDisplayNameConverter is being used for something other than ModelPropertyValues. Re-evaluate the correctness of its logic."); // Fallback mechanism object rawPropertyValue = propertyValue.Value; if (rawPropertyValue != null) { valueTypeName = rawPropertyValue.GetType().Name; } } // See if there is a regular name string propertyName = ModelUtilities.GetPropertyName(propertyValue); if (string.IsNullOrEmpty(propertyName)) { // Type only return(string.Format( culture, Resources.PropertyEditing_CollectionItemDisplayFormatType, valueTypeName)); } else { // Type and name return(string.Format( culture, Resources.PropertyEditing_CollectionItemDisplayFormatTypeAndName, valueTypeName, propertyName)); } } } return(string.Empty); }