Type as Parameter, and string[] from Linq

TBTed Bunny9/16/2022
private static string[] GetRolls(AgentHitbox agentHitbox, Type type) =>
  agentHitbox.agent.GetTraits<type>().Select(t => t.Rolls);
1. How can I use type this way? Typeof(type) didn't work either.
2. Rolls is a string[]. I need to concatenate it from the series but I haven't done that in Linq before. How do?
1.) Seems like you need generics for the function too
2.) What do you mean by concatenate? Adding the strings together? you can do that with string.Join(" ", stringArray);. You can replace " " with any string you want to have in between each string in the array :owo:
TBTed Bunny9/16/2022
1. How do I do that?
2. I need to return a string[] that is a concatenation of all the Traits' Rolls string[]s
1.) I'd try GetRolls<T>(AgentHitbox agentHitbox) => agentHitbox.agent.GetTraits<T> ...
But at compile time you wont know if T has a property Rolls so you have to restrict T to something you know, sooo
private static string[] GetRolls<T>(AgentHitbox agentHitbox) where T: SomeTypeWithRolls
  return agentHitbox.agent.GetTraits<T>().Select(t => t.Rolls).ToArray();
2.) You are using Linq, so you can use Aggregate or i believe SelectMany could work too
And don't forget ToArray at the end
TBTed Bunny9/16/2022
I'll give that a shot, thanks!
TBTed Bunny9/16/2022
Umm :catthinking: You guys rule
In general, if you find yourself using a System.Type parameter, you've probably done something wrong 🙂
TBTed Bunny9/16/2022
Ah, ok. I'll keep that in mind, thank you!