Skip to content

Commit

Permalink
Fix input handling error on component using generic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
adecler committed Dec 10, 2020
1 parent ae7d8e1 commit fda8e3e
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions BHoM_UI/Caller/Run.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
using System.Windows.Forms;
using BH.oM.Base;
using System.Collections;
using BH.oM.Reflection.Debugging;

namespace BH.UI.Base
{
Expand Down Expand Up @@ -122,6 +123,8 @@ protected virtual List<object> CollectInputs()
object input = null;
if (InputParams[i].IsSelected)
{
int preGetterEventCount = Engine.Reflection.Query.CurrentEvents().Where(x => x.Type == EventType.Error).Count();

try
{
input = m_CompiledGetters[i](m_DataAccessor, index);
Expand All @@ -131,6 +134,12 @@ protected virtual List<object> CollectInputs()
string warning = InputParams[i].DefaultValueWarning;
if (!string.IsNullOrEmpty(warning))
Engine.Reflection.Compute.RecordNote(warning);

// Temporary solution to handle error casting events that didn't throw an exception.
// Long term, we need Events of different types to better identify them instead of relying on message content.
int newErrorCount = Engine.Reflection.Query.CurrentEvents().Skip(preGetterEventCount).Where(x => x.Type == EventType.Error).Where(x => x.Message.StartsWith("Failed to cast")).Count();
if (newErrorCount > 0)
throw new Exception();
}
}
catch (Exception e)
Expand All @@ -139,6 +148,7 @@ protected virtual List<object> CollectInputs()
MethodInfo originalMethod = m_OriginalItem as MethodInfo;
if (originalInputType != null && originalInputType.IsGenericType && originalMethod != null && originalMethod.IsGenericMethod)
{
Engine.Reflection.Compute.RemoveEvents(Engine.Reflection.Query.CurrentEvents().Skip(preGetterEventCount).ToList());
UpdateInputGenericType(i);
input = m_CompiledGetters[i](m_DataAccessor, index);
}
Expand Down

0 comments on commit fda8e3e

Please sign in to comment.