Previously when you changed the C# Component input to type List Access, the data would come into the component as a List now it comes in as an IEnumberable.
This seems fairly unusable unless you are using System.Linq; and then convert it into an array .ToArray(); Am I missing something?
I think using System.Linq should be always included as default, I’m still annoyed that they took it down, and it was a long time ago. Or return to List<> instead of IEnumerable<>, it doesn’t make sense this middle ground.
As Ril says but in one line:
var points = new List<Point3d>(){ P };
a = points;
@stevebaer I made the change to make it clear the input list is immutable. We can always convert the enumerable into a list in the script. The same IEnumerable is also passed to python scripts.
It has the potential to make scripts less efficient as I can see scripters immediately making copies of the input to be able to work with List syntax. All of the workarounds described above involve creating a new list as a copy of the input IEnumerable. It is also “different” and can cause confusion with people trying to get their older scripts working in the new component.
private void RunScript(IEnumerable<Point3d> pts, out object a)
{
// pts.GetType()
// System.Collections.Generic.List`1[Rhino.Geometry.Point3d]
List<Point3d> ptList = pts as List<Point3d>;
a = null;
if (ptList == null) return;
// do some list stuff
ptList.Add(new Point3d(0,0,0));
ptList.Add(new Point3d(10,10,123));
PolylineCurve plCrv = new PolylineCurve(ptList);
a = plCrv;
}
As the Type that implements IEnumerable is a List,
what about casting to List<pts> (or whatever type you set in the Type-Hint for the variable?
my guess - this is faster then rewriting a new list - and a nice Workaround (?)
but I also might have overseen something - kind regards -tom
I think we should just pass in a List if the first thing you try to do is cast and start testing for success. There are many other collection types that implement IEnumerable.
If you want us to have an immutable list, why not just give us an ImmutableList?
Edit: introduced in 5 I guess, so not available in 4.8. Ok… seems like it would still be possible to implement what you want to give us as a Rhino class.
Hopefully that doesn’t provide the opportunity for obscure bugs if a given output goes to a few different receivers and the first data receiver in line decides to edit the list.
I just didn’t see how that could be without making (unnecessary, if the receiver isn’t supposed to edit it but has the capability to do so) copies of the list to pass to each receiver.
Dear @eirannejad
Seams like IList was choosen.
The Autocomplete in the c# editor in Grasshopper suggests an extension-Method “ToArray()”.
Where is this extension implemented ?
What I am missing - a using statement ?