diff --git a/src/runtime/McNeel.PythonEngine.cs b/src/runtime/McNeel.PythonEngine.cs index 1c93c96de..8cc4670e7 100755 --- a/src/runtime/McNeel.PythonEngine.cs +++ b/src/runtime/McNeel.PythonEngine.cs @@ -567,6 +567,9 @@ PyModule PrepareScope(string scopeName, string pythonFile) #endregion #region Marshalling + // NOTE: + // ensures incoming data is marshalled into + // closest-matching Python objects public PyObject MarshInput(object value) { switch (value) @@ -583,9 +586,9 @@ public PyObject MarshInput(object value) } return pyDict; - case IEnumerable enumerable: + case IList list: PyList pyList = new PyList(); - foreach (object obj in enumerable) + foreach (object obj in list) { pyList.Append(MarshInput(obj)); } @@ -604,6 +607,9 @@ PyObject MarshToPyObject(object value) return PyObject.FromNullableReference(_value.Borrow()); } + // NOTE: + // ensures outgoing data is marshalled into + // closest-matching dotnet objects public object MarshOutput(object value) { switch (value) @@ -611,10 +617,15 @@ public object MarshOutput(object value) case object[] array: return array.Select(i => MarshOutput(i)).ToArray(); - case List enumerable: - return enumerable.Select(i => MarshOutput(i)).ToList(); + case IList list: + var dotnetList = new List(); + foreach (object obj in dotnetList) + { + dotnetList.Append(MarshOutput(obj)); + } + return dotnetList; - case Dictionary dict: + case IDictionary dict: return dict.Select(p => { return new KeyValuePair(MarshOutput(p.Key), MarshOutput(p.Value));