Vspaste plug-in for winodws live writer

Source: Internet
Author: User
Tags mscorlib
Document directory
  • Last words

Recently, I used Windows Live writer to write study notes. When I used the code plug-in, I used the syntaxhighlight code plug-in. I found out that the vspaste plug-in is good. Copy the code in vs. Click this plug-in to copy the copied class in vs directly in the format of vs. The effect is good. However, copying text from other places cannot be pasted. Just wondering if it can replicate something from other places. So I used ildasm to check it out.

The writer plug-in is implemented by calling a function called createcontent. Open the function and find it.

Open the Il code of this function

.try  {    IL_0001:  nop    IL_0002:  ldsfld     string [System.Windows.Forms]System.Windows.Forms.DataFormats::Rtf    IL_0007:  call       bool [System.Windows.Forms]System.Windows.Forms.Clipboard::ContainsData(string)    IL_000c:  ldc.i4.0    IL_000d:  ceq    IL_000f:  stloc.1    IL_0010:  ldloc.1    IL_0011:  brtrue.s   IL_0042    IL_0013:  nop    IL_0014:  ldarg.2    IL_0015:  ldstr      "<pre class=\"code\">"    IL_001a:  ldsfld     string [System.Windows.Forms]System.Windows.Forms.DataFormats::Rtf    IL_001f:  call       object [System.Windows.Forms]System.Windows.Forms.Clipboard::GetData(string)    IL_0024:  castclass  [mscorlib]System.String    IL_0029:  call       string HTMLRootProcessor::FromRTF(string)    IL_002e:  call       string VSPaste.VSPaste::Undent(string)    IL_0033:  ldstr      "</pre><a href=\"http://11011.net/software/vspaste\">"    + "</a>"    IL_0038:  call       string [mscorlib]System.String::Concat(string,                                                                string,                                                                string)    IL_003d:  stind.ref    IL_003e:  ldc.i4.1    IL_003f:  stloc.0    IL_0040:  leave.s    IL_0062    IL_0042:  nop    IL_0043:  leave.s    IL_005d  }  // end .try 

It is easy to find that the code here is very familiar.

IL_0011:  brtrue.s   IL_0042    IL_0013:  nop    IL_0014:  ldarg.2    IL_0015:  ldstr      "<pre class=\"code\">"

If you see il_0015 and find il_0011, you can directly determine that the Code jumps to il_0042 and just skips the text conversion code. Modify il_0011: brtrue. s il_0042 to il_0011: brtrue. s il_0013 to ensure that text in the clipboard is converted to HTML. After testing, the error message of vs paste cocould not convert that content. is displayed. So let's continue to see what the code has done.

The generated string code. The general meaning is as follows:

Try {string STR = system. windows. forms. dataformats. RTF; // vs is in the format of il_0002: lds1_if (system. windows. forms. clipboard. containsdata (STR) // determines whether the clipboard format can be converted to RTF il_0007: Call {string code = "<PRE class = \" Code \ ">"; object OBJ = system. windows. forms. clipboard. getdata (STR); // get the format data code + = vspaste. undent (htmlrootprocessor. fromrtf (obj. tostring (); // call the function here to convert the RTF format to HTML il_001a: lds1_il_001f: call code + = "</PRE> <a href = \" http://11011.net/software/vspaste\ ">" + "</a>" ;}} catch {MessageBox. show ("vs paste cocould not convert that content. ");}

After talking about the above a lot, we finally convert the data in the clipboard in the RTF format into HTML code and return it. This idea is dispelled only when Microsoft uses RTF.

The class of the code I configured in my blog is 'xcode ', but the code here is changed to xcode. The following sentence <a href = \ "http://11011.net/software/vspaste\> </a> generates a car under each section of the Code, which looks uncomfortable.

So I changed the Il code

    IL_0015:  ldstr      "<pre class=\"xcode\">"    IL_001a:  ldsfld     string [System.Windows.Forms]System.Windows.Forms.DataFormats::Rtf    IL_001f:  call       object [System.Windows.Forms]System.Windows.Forms.Clipboard::GetData(string)    IL_0024:  castclass  [mscorlib]System.String    IL_0029:  call       string HTMLRootProcessor::FromRTF(string)    IL_002e:  call       string VSPaste.VSPaste::Undent(string)    IL_0033:  ldstr      "</pre>"

Then ilasm vspaste/DLL is compiled and replaced with the old file. This is quite comfortable.

 

Last words

I recently looked at the framework design. The aforementioned tools ildasm and ilasm have never tried anything. I was a little dizzy when I saw the Il code. After all, I wrote a few pieces of assembly while I was reading the book, but I didn't go into depth. So I took msdn for two hours to figure out the meaning. The stack fainted. You have to look back at the framework design carefully. This article is a free and boring post. Welcome to shoot bricks.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.