Hi guys,
I am having a rather confusing moment here… which its kind of annoying because logically I don’t understand the reason of why its happening.
Here is what I am trying to do:
Loop through a List<object>
check the type of each item, if the type of an item equals my specified type I will add it to a list. This works perfectly in a C# component but In Visual Studio it always evaluates to false. I am inputting that list under the pManager.AddGenericParameter()
in VS.
Here is the code I used to test the same logic in a C# component:
List<object> junk = new List<object>();
junk.Add(1.0);
junk.Add(SharpColor.Zero());
junk.Add("hi");
List<SharpColor> dataValues = new List<SharpColor>();
for (int i = 0; i < junk.Count; i++)
{
if (junk[i].GetType() == typeof(SharpColor))
{
dataValues.Add((SharpColor) junk[i]);
}
}
A = dataValues;
Here is the actual code in visual studio ( omitted some details for simplicity)
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddGenericParameter("Values", "V", "Values", GH_ParamAccess.list);
}
/// <summary>
/// This is the method that actually does the work.
/// </summary>
/// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
protected override void SolveInstance(IGH_DataAccess DA)
{
#region GATHER INPUT DATA
List<object> _dataValuesTemp = new List<object>();
DA.GetDataList(5, _dataValuesTemp);
#endregion
#region INITIALIZE DATA CLASS
// Create Data object
if (_dimension.EnvironmentDimension == EnvironmentDimension.Environment3D)
{
switch (m_dataCategory)
{
case DataCategory.DifussionValues:
{
if (_reset)
{
List<SharpColor> dataValues = new List<SharpColor>();
for (int i = 0; i < _dataValuesTemp.Count; i++)
{
//**************************** Always evaluates to false!
if (_dataValuesTemp[i].GetType() == typeof(SharpColor))
{
dataValues.Add( (SharpColor)_dataValuesTemp[i] );
}
//**************************** Always evaluates to false!
}
Data<SharpColor> m_Data = new GenerativeFloorPlans.Data.Data<SharpColor>(_xDim, _yDim, _zDim, m_dataCategory, dataValues);
DA.SetData(0, new GH_ObjectWrapper(m_Data));
}
break;
}
}
}
#endregion
}
Does anyone have any idea why this is happening? @DavidRutten do you have any insights? does it have to do with how the pManager.AddGenericParameter()
is defined?
Thanks!