Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions src/Engine/ProtoCore/FFI/CLRObjectMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,27 @@ public override object UnMarshal(StackValue dsObject, ProtoCore.Runtime.Context

internal static bool IsAssignableFromDictionary(Type expectedCLRType)
{
return expectedCLRType == typeof(IDictionary) ||
expectedCLRType.GetInterfaces()
.Where(i => i.IsGenericType)
.Select(i => i.GetGenericTypeDefinition())
.Contains(typeof(IDictionary<,>)) ||
expectedCLRType.IsAssignableFrom(typeof(DesignScript.Builtin.Dictionary));
if (expectedCLRType == typeof(IDictionary))
return true;

// Fast path for common generic IDictionary<,>
if (expectedCLRType.IsGenericType && expectedCLRType.GetGenericTypeDefinition() == typeof(IDictionary<,>))
return true;

// Check interfaces without LINQ
var interfaces = expectedCLRType.GetInterfaces();
for (int i = 0; i < interfaces.Length; i++)
{
var iface = interfaces[i];
if (iface.IsGenericType && iface.GetGenericTypeDefinition() == typeof(IDictionary<,>))
return true;
}

// Check assignability from DesignScript.Builtin.Dictionary
if (expectedCLRType.IsAssignableFrom(typeof(DesignScript.Builtin.Dictionary)))
return true;

return false;
}

private object ToIDictionary(StackValue dsObject, ProtoCore.Runtime.Context context, Interpreter dsi, System.Type expectedType)
Expand Down Expand Up @@ -709,9 +724,9 @@ public override StackValue Marshal(object obj, ProtoCore.Runtime.Context context
return retVal;

//5. If it is a StackValue, simply return it.
if (obj is StackValue)
if (obj is StackValue sv)
{
return (StackValue)obj;
return sv;
}

//6. Seems like a new object create a new DS object and bind it.
Expand Down
Loading