Im folgenden Beispiel _selectedMessage enthält die ursprünglichen Werte und selectedMessage enthält die geänderten Werte, die ich auf die in _selectedMessage enthaltenen Werte zurücksetzen möchte (
Code: Select all
_selectedMessage
Dies wäre der einfachste Weg, außer dass es nicht funktioniert:
Code: Select all
selectedMessage = _selectedMessage;
Code: Select all
selectedMessage.Subject = _selectedMessage?.Subject;
Code: Select all
PropertyInfo[]? properties = _selectedMessage?.GetType().GetProperties();
if (properties != null)
{
foreach (PropertyInfo property in properties)
{
// Get the name and value of each property
string? propertyName = property.Name;
object? propertyValue = property.GetValue(selectedMessage);
selectedMessage?.GetType().GetProperty(propertyName)?.SetValue(selectedMessage, propertyValue);
}
}
Was könnte ich falsch machen?