Setting an output spread in a C# node

Hello all, I’m writing a C# node that outputs some spreads and I cannot find a way to easily dump a collection of values in one of those spread outputs.

Let’s say I have a char[] somewhere, and I’d like to have all its items in an output pin of type Spread<string>. Here’s what I’d like to do in pseudo-code :

public static void Foo(int bar, out Spread<string> MyOutputSpread)

    char[] baz = {'a', 'b', 'c'};

    for(var item in baz)

Workaround I’ve found is to create a “temporary” List<string>, add all my stuff inside and then do

MyOutputSpread = myTempList.ToSpread();

But that does not look graceful.

Any suggestion ?

Thanks in advvvvance!


Don’t you need a SpreadBuilder for this?

Does Spread support AddRange?


Yes, in VL I’d use a SpreadBuilder for such a thing, I tried some things with Intellisense in that direction but could not achieve anything.

I did


But then it complains about Use of unassigned out parameter MyOutputSpread, but I could not find a constructor for Spread<T> (so that I could do MyOutputSpread = new Spread<T> before the loop)

Nope, did not see such a thing.

Thanks for the suggestions guys!

With VL.Lib.Collections in your using statements

Option 1)

MyOutputSpread = baz.Select(x => x.ToString()).ToSpread();

Option 2)

var builder = new SpreadBuilder<string>();
foreach (var item in baz)
MyOutputSpread = builder.ToSpread();

Thanks @Elias, option 1 looks cool :)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.