104
0xTJ
7y

*Cuts 7 slow lines of code down to 1 fast line of code*
*Looks around to see if coworkers can see me*
*Pumps both fists in the air*

Comments
  • 4
    Removed line breaks?
    Joking I'm curious to know the "before" and "after" if you can't share code, at least the logic. No bad intention but I always like to see what others do to improve code :)
  • 4
    @gitpush Essentially, I have a 2D array which I use as a guide for which data means what from the inputs, and where to put it in the output. Between those two steps, the array determines in which field or property of a class each piece of data is stored. I want to make the 2D array easy to configure in source, perhaps later user-configurable during excecution.
    I initially had it determining where to put stuff every loop excecution, because some of the pieces of data go into fields, others into properties, and I had to determine which one was which each time. I knew this was inneficient, but it worked.
  • 3
    @gitpush @0xTJ I've since spent a couple hours struggling against VS to get it to be able to run a set those properties and fields according to what is determined only once, but had issues as the FieldInfo and PropertyInfo (which both inherit from MemberInfo) classes don't quite play nice enough. Eventually, I got it working by storing MethodInfo for each element in the top level of the 2D array, so I don't have to determine the subclass everytime, I just run the method on the subclass instance, because I know it's there. Probably not the safest way of doing things, but it should be safe enough for me.
    What I've written probably doesn't make sense without seeing the code, but I should probably get off my phone, and keep working.
  • 2
    @0xTJ From what I understood you were keeping references to methods in your array so that based on input you decide which function you need to produce output? Maybe I'm wrong, but I'd stay away from Arrays and go with something similar to this: https://stackoverflow.com/a/...

    Maybe the original question is not related to your case, but if you can filter on an array you can filter on a class with cluster members using Lambda/LINQ as they have a better performance than arrays
  • 3
    @gitpush Thanks for the suggestion. I know that I'm not doing things in the best way, and I'll give that a try, though it's just an internal tool, so I'll leave it as it is if it doesn't go easily.
  • 3
    Cheering? I do this.
  • 1
    I *AM* THE MASTER COMMANDER!
Add Comment