According to MSDN MethodRental Class allows to change method body of dynamic modules. However because of its limitations I cannot think of practical usages for it. Google did not help me either.
Any ideas what the class can be used for?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This is similar in spirit to
ICorProfilerCallback::JITCompilationStartedwhen paired withICorProfilerInfo::SetILFunctionBody, but with more constraints. TheICorProfiler*classes can be used to do runtime instrumentation for almost any managed method. There are profilers and debuggers that use these to collect information about a running process.You could use
MethodRentalto instrument code for diagnostic purposes. Some examples:You could also use
MethodRentalto enhance the functionality of existing code. Aspect-oriented programming comes to mind. You could ‘weave’ in security, logging, or other cross-cutting design concerns into existing code. This would require some other facility (XML, a C# library) to express your aspects, however.Finally, you could use
MethodRentalto “detour” existing code, i.e. intercept method calls to create a kind of runtime polymorphism. For example, if you have client code that uses some dynamically-generated classRegistryStoreto get some configuration viaGetConfig, you could rewrite the method’s IL to change the implementation ofRegistryStore.GetConfigto use the filesystem instead. You could do this without having to change the client code.