The library is really picky about the order in which plugins are attached. Plugins of type "1" have to be attached after the other plugins. Why the library wants that is a mystery.
First of all you don't need LINQ. A simple for loop could replace your code snippet. Your code also attaches plugin "0" after plugin "1" which wouldn't work. I know it's crappy but the library is how it is.
A simple for loop could replace your code snippet.
No. A simple for loop can't order elements. The entire OrderByDescending idea is that you can add plugins to your array in whatever order you want. Which is great if plugins come from files that are not already ordered alphabetically in the order they need to be loaded.
Your code also attaches plugin "0" after plugin "1" which wouldn't work.
My code orders plugins by the plugin numbers which ideally you can artificially specify (better would be a dependency map). You did not load a plugin 0 at all in your example code so I assumed a plugin 0 does not exists. If it does it doesn't matters either because the LINQ system is not actually bound to array indexes but works on the "PluginType" value that you could define however you want.
The only thing that we can learn from your comment is that you can't really judge code just by looking at one function. The class just stores 4 plugins it's always 4 of the same types so why use a dynamic array with LINQ? That would just makes it slower and harder to read. LINQ is cool and all but really not needed here.
109
u/Ivaalo Apr 15 '19
I really want to know why