c# - Looking for clarification on the behavior of Reflection.Emit when used with a lambda expression -


specifically, attempting create method takes in lambda expression , spins expression off main method of temporary console application @ run time in order allow spinning off small sections of code separate process @ run-time can better isolate memory behavior (i did application domains ran other problems there due limitations use case). sort of limited fork.

this relatively straightforward if can assumed lambda expression contains local variables, struggling figuring out how i'll have (and how best way go is) if expression makes use of non-local variables (that is, variable exists within enclosing scope, per comment below. couldn't think of better way @ time phrase "a variable not within local scope accessible").

to knowledge, non-local variable means field load instruction of sort generated within msil. while can potentially make copy of required objects/fields in secondary application, if try take msil of lambda expression as-is via methodbody.getilasbytearray(), generated code (i believe) contain field load instructions targeting metadata table entries may (most be) different metadata table entries copies of objects/fields created in console application via reflection.emit.

further complicating matter closure, think/if remember correctly means non-local reference within lambda expression body cause object created hold values (copies? references? don't quite recall). don't need worry though, because won't lambda expression once emitted second application in particular use case? if i'm getting method body, think i'd end sidestepping usual handling closure?

ultimately have 2 questions:

a. there i'm missing in general understanding of how whole process work

b. have go , field table references in msil , if so, pragmatic way go this? there way reflection.emit make these adjustments me?

of course, i'd happy hear if there less frustrating way accomplish attempting , open suggestions.

accessing local variables outside anonymous method/lambda expression creates closure object holding variables. assuming pass lambda delegate, target property contain outside state of delegate (something displayclass). unless modify cil of method, won't real-time communication via class remote process, can serialize , pass remote process. of course, if delegate depends on static fields, left analyzing method find them , serialize them (using system.linq.expressions helpful).

now, if remote process references main assembly, find displayclass there, if not, have serialize type , build on other side, hooking method using appdomain.typeresolve. can deserialize object created type.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -