mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-22 08:29:18 +01:00
Add a verbose log message, bring type selection out from the exception
This commit is contained in:
parent
53f7e9a4f4
commit
e2dfcca482
1 changed files with 20 additions and 17 deletions
|
|
@ -5,6 +5,7 @@ using System.Reflection;
|
||||||
|
|
||||||
using Dalamud.Plugin.Ipc.Exceptions;
|
using Dalamud.Plugin.Ipc.Exceptions;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace Dalamud.Plugin.Ipc.Internal
|
namespace Dalamud.Plugin.Ipc.Internal
|
||||||
{
|
{
|
||||||
|
|
@ -147,26 +148,28 @@ namespace Dalamud.Plugin.Ipc.Internal
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
// If type -> type fails, try to find an object that matches.
|
Log.Verbose($"Could not convert {obj.GetType().Name} to {type.Name}, will look for compatible type instead");
|
||||||
var sourceType = obj.GetType();
|
}
|
||||||
var fieldNames = sourceType.GetFields(BindingFlags.Public | BindingFlags.Instance)
|
|
||||||
.Select(f => f.Name);
|
|
||||||
var propNames = sourceType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
|
||||||
.Select(p => p.Name);
|
|
||||||
|
|
||||||
var assignableTypes = type.Assembly.GetTypes()
|
// If type -> type fails, try to find an object that matches.
|
||||||
.Where(t => type.IsAssignableFrom(t) && type != t)
|
var sourceType = obj.GetType();
|
||||||
.ToArray();
|
var fieldNames = sourceType.GetFields(BindingFlags.Public | BindingFlags.Instance)
|
||||||
|
.Select(f => f.Name);
|
||||||
|
var propNames = sourceType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||||
|
.Select(p => p.Name);
|
||||||
|
|
||||||
foreach (var assignableType in assignableTypes)
|
var assignableTypes = type.Assembly.GetTypes()
|
||||||
|
.Where(t => type.IsAssignableFrom(t) && type != t)
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
foreach (var assignableType in assignableTypes)
|
||||||
|
{
|
||||||
|
var matchesFields = assignableType.GetFields().All(f => fieldNames.Contains(f.Name));
|
||||||
|
var matchesProps = assignableType.GetProperties().All(p => propNames.Contains(p.Name));
|
||||||
|
if (matchesFields && matchesProps)
|
||||||
{
|
{
|
||||||
var matchesFields = assignableType.GetFields().All(f => fieldNames.Contains(f.Name));
|
type = assignableType;
|
||||||
var matchesProps = assignableType.GetProperties().All(p => propNames.Contains(p.Name));
|
break;
|
||||||
if (matchesFields && matchesProps)
|
|
||||||
{
|
|
||||||
type = assignableType;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue