Skip to content

Need a way to override ordering when one variable depends on another being initialized first #1066

Open
@chance2now

Description

@chance2now

I just had to fix an "object not initialized" error and found that it was caused by CodeMaid reordering my declarations and putting one before another that it depends on. Basically, I have array A that is used for a variety of things and one of them is that array B is declared with an initializer similar to "static int[] B = new int[LookupA(someConstant)];". LookupA is a formula that calculates an index into A based on a constant that can be tweaked as needed, and the value in A at that index is used to declare the size of B.

The order in which the two array declarations are placed can depend on access modifiers and how they are named (and possibly other things that I'm not aware of) but I need them to always be in a specific order regardless of any other settings. It might be possible to analyze the source for dependencies, but this would add quite a bit of complexity. Another way could be to add some additional solution-dependent options that say
"Always initialize ____ before ____."

In my case, one is private and one is internal so I can work around this by changing the order based on access level, and if that weren't possible I could still rename one or the other to change the alphabetical sort order, or just move the initialization into the static constructor. But it would be nice if this could be guaranteed so that wouldn't be necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions