Skip to content

Commit

Permalink
fix(PropArgumentSet): fix Duplicate() for string value before IEnumer…
Browse files Browse the repository at this point in the history
…able
  • Loading branch information
MingboPeng committed May 16, 2023
1 parent b176c9e commit 888b5e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Types;

namespace Ironbug.Grasshopper.Component
{
Expand Down
22 changes: 11 additions & 11 deletions src/Ironbug.HVAC/BaseClass/IB_PropArgumentSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public List<T> GetListByKeyInit<T>(string propertyName, Func<List<T>> initDefaul
this.SetByKey(propertyName, def);
return def;
}
else if (prop is IEnumerable ls)
else if ((prop is IEnumerable ls) && !(prop is string)) // string is IEnumerable, so check and exclude it
{
if (prop is List<T> lst)
return lst;
Expand Down Expand Up @@ -159,8 +159,6 @@ internal void OnDeserializedMethod(StreamingContext context)
throw new ArgumentException("Failed to deserialize", ex);
}



}


Expand All @@ -176,16 +174,14 @@ public IB_PropArgumentSet Duplicate()

static object Duplicate(object obj)
{
if (obj is IEnumerable enu)
{
return enu.Cast<object>().Select(_ => Duplicate(_));
}
if (obj is string st)
return st;
else if(obj is IEnumerable enu)
return enu.Cast<object>().Select(_ => Duplicate(_)).ToList();
else if (obj is IB_ModelObject mo)
return mo.Duplicate();
else
{
else
return obj;
}
}

public override bool Equals(object obj) => this.Equals(obj as IB_PropArgumentSet);
Expand All @@ -211,7 +207,11 @@ public bool Equals(IB_PropArgumentSet other)
static bool AreSame(object o1, object o2)
{
var same = true;
if (o1 is IEnumerable enu)
if (o1 is string o1s) // string is IEnumerable
{
return o1s.Equals(o2?.ToString());
}
else if(o1 is IEnumerable enu)
{
var o1m = enu.Cast<object>();
var o2m = (o2 as IEnumerable)?.Cast<object>();
Expand Down

0 comments on commit 888b5e4

Please sign in to comment.