il

How to use OpCodes.Call to generate this code

匆匆过客 提交于 2019-12-12 04:54:20
问题 This question is related to: Casting items of a collection with code generation Since the previous question was not clear enough, here is what I need help with precisely. How to use OpCodes.Call to generate this code: return Enumerable.ToList<Potato>(Eumerable.Cast<Potato>(_proxyPotatoes)); Here is an example of what I'm trying to do: public class Potato { } public class ProxyPotato : Potato { } public class Stew { private ICollection<ProxyPotato> _proxyPotatoes; //This is the code I would

C# Reflection IL - Understanding how values are copied

本秂侑毒 提交于 2019-12-12 02:27:51
问题 I'm trying to improve the performance of a certain part of my program which involves deep cloning the same object graph over and over across multiple threads. Currently I use serialization which is a nice easy implementation but I'd like something faster. I came across the idea of IL cloning and am trying to work with some code found here (Whizzo's Blog). I don't really get IL as yet, so I'm hoping someone can help a little bit and explain some of the stuff to me (I imagine this is the first

Can PEVerify tell me the severity of each error?

感情迁移 提交于 2019-12-12 01:19:22
问题 I'm modifying an assembly using Mono.Cecil , and I want to check it for validity (whether the result will run at all). I'm trying to use PEVerify , but I'm having a problem. It was designed for ensuring code is verifiable, so it just says ERROR whether the error means the IL is completely invalid and will not execute, or whether it's a verifiability issue that would be ignored in full trust. Here are some examples: Using pointers and the like. Not setting .locals init when the method has

Why Managed module Is faster than Unmanaged module in C# [closed]

耗尽温柔 提交于 2019-12-11 06:34:36
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I reading a book( CLR via c#)in the book writer speak about IL and managed module that managed module compiling in native cpu code and then execute in the book writer said that Managed module Is faster than

Redirecting to a dynamic method from a generic event handler

末鹿安然 提交于 2019-12-11 05:29:15
问题 I'm trying to write a class that's to be used to trigger a call to a method from an arbitrary event but I'm stuck as I simply cannot figure out a way to reference 'this' from emitted MSIL code. This example should describe what I'm looking for: class MyEventTriggeringClass { private object _parameter; public void Attach(object source, string eventName, object parameter) { _parameter = parameter; var e = source.GetType().GetEvent(eventName); if (e == null) return; hookupDelegate(source, e); }

Mono.Cecil: call base class' method from other assembly

泄露秘密 提交于 2019-12-10 21:49:28
问题 How can I get a MethodReference to a base class' method by name? I've tried type.BaseType.Resolve().Methods; and if I add the dll containing the base class to the assemblyresolver it returns the methods. But if I add a call using MSILWorker.Create(OpCodes.Call, baseMethod); (where baseMethod was found by foreaching Methods from the resolved TypeDefinition) the resulting IL is unreadable, even Reflector freezes and quits. Now some IL: if calling private method on type: call instance void

Defensive anti-multithreading class implementation

和自甴很熟 提交于 2019-12-10 21:42:02
问题 I have an object that is not safe for multithreaded applications (in several ways), and I want to provide an internal check to make sure that critical methods are not accessed concurrently. Question What techniques should I employ to detect and prevent multiple threads from accessing my class? Is it sufficient to track the Thread.ID on all methods, properties, etc. that the consumer may use? 回答1: Just document that it isn't thread safe. That's the convention used by the classes in .NET. 回答2:

IL / CLR / DLR References?

让人想犯罪 __ 提交于 2019-12-10 18:31:42
问题 I'm wanting to learn more about IL and CLR / DLR under the hood. A friend of mine recommended the book "Inside Microsoft .NET IL Assembler", but since it came out in 2002 I fear it's pretty out of date at this point. Does anyone have any more up-to-date books or websites that can be used by someone who understands .NET languages to learn more about the inner workings of IL and the CLR? 回答1: Perhaps my answer is a bit late now, but the book "MS Press - Inside Microsoft .NET IL Assembler" is

Dynamic IL method causes “Operation could destabilize the runtime”

扶醉桌前 提交于 2019-12-10 17:12:41
问题 System.Security.VerificationException: Operation could destabilize the runtime. at Connance.CommunicatorApi.ReportApiClient.AcknowledgeRecallsAsyncDynamicHandler(Object , AcknowledgeRecallsCompletedEventArgs ) That's the error I'm getting. What I'm trying to do (background) is create a global event handler for a class of methods. I'm working with a Static Proxy in WCF and I need to create a layer which tracks all the calls and returns to all of the WCF web methods. Unfortunately, WCF strongly

Generating IL for 2D Arrays

爱⌒轻易说出口 提交于 2019-12-10 16:17:20
问题 I want to generate IL for the 2D array construction, using System.Reflection.Emit namespace. My C# code is Array 2dArr = Array.CreateInstance(typeof(int),100,100); Using ildasm , I realized that following IL Code is generated for the above C# code. IL_0006: call class [mscorlib]System.Type [mscorlib]System.Type::GetTypeFromHandle(valuetype [mscorlib]System.RuntimeTypeHandle) IL_000b: ldc.i4.s 100 IL_000d: ldc.i4.s 100 IL_000f: call class [mscorlib]System.Array [mscorlib]System.Array: