Sunday, 15 May 2011

c# JIT and static constructors again -



c# JIT and static constructors again -

okay have little problem 2 things there

following situation: got abstract class "emitter". class has static dictionary maintain track of types deriving it.

for illustration have class "linearemitter" class has static constructor. constructor adds typeof(linearemitter) dictionary. problem now, when want utilize static dictionary emitter (static method "getmeemitterfromid(int id)") can happen, children of "emitter" (e.g. linearemitter) not initialized (im reading info file , id classes in "emitter" , initialize instance that).

how can create sure every child-class initialized before?(has written in dictionary) ?

of course of study others should utilize library, , should utilize static constructor add together classes "emitter"'s dictionary

any ideas?

eric lippert had great series static constructors.

static constructors part one, static constructors part two, static constructors part three, static constructors part four

to sum useful bit in case: static constructors invoked by

just before first access of static method/field. just before first access instance of type.

so either invoke static method initialize() or instantiate class of type derived emitter.

that aside, i'm sure there's improve way implement problem because way static initializers run alter on different .net / clr versions , wouldn't rely on if don't have to.

c# static constructor jit

No comments:

Post a Comment