Resolved runtime type conversion issue with DefaultConnectionInfo when loading from a serialized source

This commit is contained in:
David Sparer
2016-08-12 11:18:17 -06:00
parent 8d3ba881e5
commit 0df478d2aa

View File

@@ -1,4 +1,7 @@
using System;
using System.ComponentModel;
using mRemoteNG.Connection.Protocol;
using mRemoteNG.Tools;
namespace mRemoteNG.Connection
@@ -6,7 +9,8 @@ namespace mRemoteNG.Connection
public class DefaultConnectionInfo : ConnectionInfo
{
public static DefaultConnectionInfo Instance { get; } = new DefaultConnectionInfo();
private readonly string[] _excludedProperties = { "Parent" };
private readonly string[] _excludedProperties = { "Parent", "Name", "Panel", "Hostname", "Port", "Inheritance",
"OpenConnections", "IsContainer", "IsDefault", "PositionID", "ConstantID", "TreeNode", "IsQuickConnect", "PleaseConnect" };
private DefaultConnectionInfo()
{
@@ -19,9 +23,15 @@ namespace mRemoteNG.Connection
var connectionProperties = GetProperties(_excludedProperties);
foreach (var property in connectionProperties)
{
var propertyFromSettings = typeof(TSource).GetProperty(propertyNameMutator(property.Name));
var valueFromSettings = propertyFromSettings.GetValue(sourceInstance, null);
property.SetValue(Instance, valueFromSettings, null);
var propertyFromSource = typeof(TSource).GetProperty(propertyNameMutator(property.Name));
var valueFromSource = propertyFromSource.GetValue(sourceInstance, null);
var descriptor = TypeDescriptor.GetProperties(Instance)[property.Name];
var converter = descriptor.Converter;
if (converter != null && converter.CanConvertFrom(valueFromSource.GetType()))
property.SetValue(Instance, converter.ConvertFrom(valueFromSource), null);
else
property.SetValue(Instance, valueFromSource, null);
}
}