Thursday 15 April 2010

c# - Decompiled assembly - unusual code -


I weakened an assembly using ILSPT, public class customsstream : Network Stream {Private Event Handler & lt; Custom Event Egg & gt; SomeEvent; Public events event handler & lt; Custom Event Egg & gt; Add SomePublicEvent {add {EventHandler & lt; CustomEventArgs & gt; EventHandler = this.someEvent; Eventhandler & LT; CustomEventArgs & gt; EventHandler2; Do {eventHandler2 = eventHandler; Eventhandler & LT; CustomEventArgs & gt; Value2 = (Event Handler & lt; CustomEventErgies & gt;) Representative Cobain (eventhandsler 2, value); EventHindler = Interlock Comprex Exchange and lieutenant; EventHandler; & Lt; CustomAventAge & gt; & Gt; (Referee this Somewant, Value 2, EventHandler 2); } While (eventHandler! = EventHandler2); } Remove {// Similar stuff ...}}}

In the next code, it seems that a real incident is set to fire a personal representative:

  if (some! = Null & amp; amp; something; ele =!) {This.someEvent (this, new CustomEventArgs (someArg)); }   

Question: Can anyone guess what the idea behind this custom accessor could be, assuming that some "compile / divide magic" was not done? I am not very familiar with IL, BTW ...

(Side note: application is multi-threaded and uses networking, obviously.)

This is a new event handler code generated by the compiler. It was launched in C # 4 (C # version was different)

Interlock Comparx Exchange compares the first argument with the third, and if they are equal, then the second argument changes with the other. This is a thread-safe operation Loop is used for any case when a variable eventHandler2 and check Prior to this, a thread changes to this representative. In this case, interlock Compressed Exchange does not execute the exchange, the position of the loop is correct and does not evaluate the next attempt.

Generates simple code in C # 3 event handlers:

 Add  lock (this) {changed = change = value;  

>



No comments:

Post a Comment