Skip to content

Commit

Permalink
Simplification from @adecler suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
IsakNaslundBh committed Jan 18, 2021
1 parent 8d6a58c commit 16938f7
Showing 1 changed file with 3 additions and 31 deletions.
34 changes: 3 additions & 31 deletions BHoM_UI/Components/UI/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,40 +104,12 @@ protected override void SetComponentDetails(MethodBase method)

public override object Run(List<object> inputs)
{
if (m_CompiledFunc != null)
{
object returnValue = null;
MethodInfo method = m_OriginalItem as MethodInfo;
try
{
returnValue = m_CompiledFunc(inputs.ToArray());
}
catch (InvalidCastException e)
{
MethodInfo originalMethod = m_OriginalItem as MethodInfo;
if (originalMethod != null && originalMethod.IsGenericMethod)
{
// Try to update the generic method to fit the input types
method = Engine.Reflection.Compute.MakeGenericFromInputs(originalMethod, inputs.Select(x => x.GetType()).ToList());
m_CompiledFunc = method.ToFunc();
returnValue = m_CompiledFunc(inputs.ToArray());
}
else
throw e;
}
object returnValue = base.Run(inputs);

return new UnitTest() { Method = method, Data = new List<TestData>() { new TestData(inputs, SeparateOutputs(returnValue)) } };
}
else if (InputParams.Count <= 0)
{
BH.Engine.Reflection.Compute.RecordWarning("This is a magic component. Right click on it and <Select a method>");
return null;
}
if (m_CompiledFunc != null)
return new UnitTest() { Method = m_OriginalItem as MethodBase, Data = new List<TestData>() { new TestData(inputs, SeparateOutputs(returnValue)) } };
else
{
BH.Engine.Reflection.Compute.RecordError("The component is not linked to a method.");
return null;
}
}

/*************************************/
Expand Down

0 comments on commit 16938f7

Please sign in to comment.