Skip to content

Commit

Permalink
Overwrite MethodCaller.Write() so it saves its original method
Browse files Browse the repository at this point in the history
  • Loading branch information
adecler committed May 16, 2020
1 parent cae7191 commit 5a3f63f
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion BHoM_UI/Templates/MethodCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*/

using BH.Engine.Reflection;
using BH.Engine.Serialiser;
using BH.oM.Base;
using BH.oM.Reflection.Attributes;
using BH.oM.UI;
using System;
Expand Down Expand Up @@ -126,7 +128,7 @@ public override object Run(object[] inputs)
if (Method is MethodInfo && m_OriginalMethod != null && m_OriginalMethod.IsGenericMethod)
{
// Try to update the generic method to fit the input types
Method = Compute.MakeGenericFromInputs(m_OriginalMethod, inputs.Select(x => x.GetType()).ToList());
Method = Engine.Reflection.Compute.MakeGenericFromInputs(m_OriginalMethod, inputs.Select(x => x.GetType()).ToList());
m_CompiledFunc = Method.ToFunc();
return m_CompiledFunc(inputs);
}
Expand All @@ -146,6 +148,25 @@ public override object Run(object[] inputs)
}
}

/*************************************/

public override string Write()
{
try
{
CustomObject component = new CustomObject();
component.CustomData["SelectedItem"] = (m_OriginalMethod == null) ? SelectedItem : m_OriginalMethod;
component.CustomData["InputParams"] = InputParams;
component.CustomData["OutputParams"] = OutputParams;
return component.ToJson();
}
catch
{
BH.Engine.Reflection.Compute.RecordError($"{this} failed to serialise itself.");
return "";
}
}


/*************************************/
/**** Private Methods ****/
Expand Down

0 comments on commit 5a3f63f

Please sign in to comment.