自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

VS項(xiàng)目整體重命名工具

開(kāi)發(fā) 開(kāi)發(fā)工具 后端
不再為項(xiàng)目重命名和修改命名空間而煩惱,簡(jiǎn)單幾個(gè)字,但是開(kāi)發(fā)加上測(cè)試大量項(xiàng)目,前前后后竟然跨越了1個(gè)月,汗。。。不過(guò)真正的開(kāi)發(fā)時(shí)間可能2-3天的樣子。

VS項(xiàng)目整體重命名工具

不再為項(xiàng)目重命名和修改命名空間而煩惱,簡(jiǎn)單幾個(gè)字,但是開(kāi)發(fā)加上測(cè)試大量項(xiàng)目,前前后后竟然跨越了1個(gè)月,汗。。。不過(guò)真正的開(kāi)發(fā)時(shí)間可能2-3天的樣子。

一.介紹

1.雖然說(shuō)我們平常不會(huì)經(jīng)常出現(xiàn)項(xiàng)目重命名的情況,但是一旦出現(xiàn),修改起來(lái)還是一項(xiàng)比較大的工程,并且還不一定修改完整。

2.當(dāng)團(tuán)隊(duì)發(fā)展到一定程度的時(shí)候,基本上都有了自己固定的一些WEB/Winform開(kāi)發(fā)框架和通用項(xiàng)目模版,這樣就會(huì)出現(xiàn)修改項(xiàng)目名稱,命名空間等結(jié)構(gòu)的情況。

3.噠噠噠噠噠噠,不說(shuō)第三了。親,沒(méi)了。@_@

二.功能

 

1.自動(dòng)重命名關(guān)聯(lián)的各種文件,并且支持自定義擴(kuò)展。

2.自動(dòng)檢測(cè)文件編碼格式,處理讀取不同編碼格式時(shí)出現(xiàn)的亂碼問(wèn)題。(當(dāng)項(xiàng)目?jī)?nèi)包含中文的時(shí)候)

3.自動(dòng)修改sln和csproj文件中的引用關(guān)系,并且根據(jù)文件名稱修改文件夾名稱。

4.清理BIN目錄和OBJ目錄,已經(jīng)項(xiàng)目產(chǎn)生的不必要的垃圾文件,可單獨(dú)使用。

5.每個(gè)csproj都是執(zhí)行單獨(dú)修改,然后更新關(guān)聯(lián)引用,并記住修改過(guò)的引用。

6.輸入項(xiàng)目新名詞的文本框加入了選詞功能(文本框本身雙擊內(nèi)容是全選的效果)。

7.自己試一下把。+_+

三.演示與截圖

 

1.VS的觀察 

更新前的VS項(xiàng)目解決方案

更新后的VS項(xiàng)目解決方案

2.系統(tǒng)資源管理器的觀察

更新前的文件夾結(jié)構(gòu)

更新后的文件夾結(jié)構(gòu)

3.軟件使用截圖

1.打開(kāi)軟件顯示很簡(jiǎn)單的打開(kāi)解決方案的視圖。

[[67899]]

2.選擇解決方案打開(kāi)后,會(huì)自動(dòng)加載該目下所有的csproj文件。

3.點(diǎn)擊【軟件設(shè)置】會(huì)出現(xiàn)其他需要修改關(guān)聯(lián)的文件后綴名,你也可以直接寫文件全名。

你也可以給輸入新名稱的文本框添加選詞分隔符,以達(dá)到你所需要的自動(dòng)選詞效果。

#p#

 

 四.代碼和思路

1.文本框智能選詞功能的實(shí)現(xiàn)。

  1. public delegate void AutoSelectTextBoxDoubleclick(object sender, MouseEventArgs e);  
  2.      /// <summary>  
  3.      /// 智能選擇文本控件,親,這個(gè)類copy走就可以使用喲  
  4.      /// </summary>  
  5.      public class AutoSelectTextBox : TextBox  
  6.      {  
  7.          const int WM_LBUTTONDBLCLK = 0x0203;  
  8.          MouseEventArgs e;  
  9.    
  10.          /// <summary>  
  11.          /// 是否啟用智能選擇  
  12.          /// </summary>  
  13.          [System.ComponentModel.Description("是否啟用智能選擇")]  
  14.          public bool EnableAutoSelect  
  15.          {  
  16.              get;  
  17.              set;  
  18.          }  
  19.    
  20.          private List<char> splitChar;  
  21.    
  22.          /// <summary>  
  23.          /// 選擇判斷分隔符,默認(rèn) . 號(hào)  
  24.          /// </summary>  
  25.          [System.ComponentModel.Description("判斷選擇分隔符,默認(rèn) . 號(hào)")]  
  26.          [System.ComponentModel.Browsable(false)]  
  27.          public List<char> SplitChar  
  28.          {  
  29.              get { return splitChar; }  
  30.              set { splitChar = value; }  
  31.          }  
  32.    
  33.          /// <summary>  
  34.          /// 智能選擇文本框雙擊事件  
  35.          /// </summary>  
  36.          public event AutoSelectTextBoxDoubleclick AutoSelectTextMouseDoubleclick;  
  37.    
  38.          protected override void WndProc(ref Message m)  
  39.          {  
  40.    
  41.              if (EnableAutoSelect && m.Msg == WM_LBUTTONDBLCLK)  
  42.              {  
  43.                  Point p = this.PointToClient(MousePosition);  
  44.                  e = new MouseEventArgs(MouseButtons.Left, 2, p.X, p.Y, 0);  
  45.                  if (AutoSelectTextMouseDoubleclick != null)  
  46.                  {  
  47.                      AutoSelectTextMouseDoubleclick(this, e);  
  48.                  }  
  49.                  else 
  50.                  {  
  51.                      MouseDoubleClickAutoSelect(e);  
  52.                  }  
  53.                  return;  
  54.    
  55.              }  
  56.              else 
  57.              {  
  58.                  base.WndProc(ref m);  
  59.              }  
  60.          }  
  61.    
  62.          /// <summary>  
  63.          /// 智能選擇實(shí)現(xiàn)  
  64.          /// </summary>  
  65.          private void MouseDoubleClickAutoSelect(MouseEventArgs e)  
  66.          {  
  67.              if (this.Text != "")  
  68.              {  
  69.                  int pint = this.GetCharIndexFromPosition(e.Location);  
  70.                  int len = this.Text.Length;  
  71.                  int left = pint, right = pint;  
  72.    
  73.                  while (left >= 0)  
  74.                  {  
  75.                      char lchar = this.Text[left];  
  76.                      if (CheckSpiltChar(lchar))  
  77.                      {  
  78.                          break;  
  79.                      }  
  80.                      left--;  
  81.                  }  
  82.                  while (right <= len - 1)  
  83.                  {  
  84.                      char rchar = this.Text[right];  
  85.                      if (CheckSpiltChar(rchar))  
  86.                      {  
  87.                          break;  
  88.                      }  
  89.                      right++;  
  90.                  }  
  91.                  //必須有字符可選  
  92.                  if (right - (left + 1) > 0)  
  93.                  {  
  94.                      this.Select(left + 1, right - (left + 1));  
  95.                  }  
  96.              }  
  97.    
  98.          }  
  99.    
  100.    
  101.    
  102.          /// <summary>  
  103.          /// 檢查  
  104.          /// </summary>  
  105.          /// <param name="source"></param>  
  106.          /// <returns></returns>  
  107.          private bool CheckSpiltChar(char source)  
  108.          {  
  109.              if (SplitChar != null)  
  110.              {  
  111.                  foreach (char c in SplitChar)  
  112.                  {  
  113.                      if (char.Equals(source, c))  
  114.                      {  
  115.                          return true;  
  116.                      }  
  117.                  }  
  118.                  return false;  
  119.              }  
  120.              else 
  121.              {  
  122.                  return char.Equals(source, '.');  
  123.              }  
  124.          }  
  125.    
  126.      } 

解釋:該自動(dòng)完成選詞功能需要重寫文本框的消息機(jī)制,其中 WM_LBUTTONDBLCLK = 0x0203 為鼠標(biāo)雙擊消息,然后重寫WndProc該事件。
為什么我重新寫雙擊消息,而不是用文本框本身的雙擊事件,是因?yàn)楸旧淼碾p擊事件會(huì)處理一些其他內(nèi)容,并且會(huì)出現(xiàn)先選中全部?jī)?nèi)容然后再自動(dòng)選詞的閃爍問(wèn)題,
有興趣的同學(xué)可以試一下就知道了。

2.老調(diào)重彈自動(dòng)識(shí)別文件編碼問(wèn)題,大部分的解決方案都不太理想,基本都是讀取文件2-4位,判斷字節(jié)大小,來(lái)決定文件編碼類型。
這樣的思路只是其中之一,當(dāng)我郁悶至極的時(shí)候突然想到ITextSharp控件(重量級(jí)語(yǔ)言高亮編輯器),找到源碼,發(fā)現(xiàn)了一塊編碼自動(dòng)識(shí)別的功能。

下面代碼是ITextSharp控件中文件編碼識(shí)別的源碼,這個(gè)我發(fā)現(xiàn)比百度和google出來(lái)的效果好很多,基本上無(wú)識(shí)別錯(cuò)誤情況,基本100%識(shí)別正確。
但是帶來(lái)的后果是要檢查一段內(nèi)容前面很大一段內(nèi)容,用性能換編碼識(shí)別精度。

  1. public static StreamReader OpenStream(Stream fs, Encoding defaultEncoding)  
  2.          {  
  3.              if (fs == null)  
  4.                  throw new ArgumentNullException("fs");  
  5.    
  6.              if (fs.Length >= 2)  
  7.              {  
  8.                  // the autodetection of StreamReader is not capable of detecting the difference  
  9.                  // between ISO-8859-1 and UTF-8 without BOM.  
  10.                  int firstByte = fs.ReadByte();  
  11.                  int secondByte = fs.ReadByte();  
  12.                  switch ((firstByte << 8) | secondByte)  
  13.                  {  
  14.                      case 0x0000: // either UTF-32 Big Endian or a binary file; use StreamReader  
  15.                      case 0xfffe: // Unicode BOM (UTF-16 LE or UTF-32 LE)  
  16.                      case 0xfeff: // UTF-16 BE BOM  
  17.                      case 0xefbb: // start of UTF-8 BOM  
  18.                          // StreamReader autodetection works  
  19.                          fs.Position = 0;  
  20.                          return new StreamReader(fs);  
  21.                      default:  
  22.                          return AutoDetect(fs, (byte)firstByte, (byte)secondByte, defaultEncoding);  
  23.                  }  
  24.              }  
  25.              else 
  26.              {  
  27.                  if (defaultEncoding != null)  
  28.                  {  
  29.                      return new StreamReader(fs, defaultEncoding);  
  30.                  }  
  31.                  else 
  32.                  {  
  33.                      return new StreamReader(fs);  
  34.                  }  
  35.              }  
  36.          }  
  37.    
  38.          static StreamReader AutoDetect(Stream fs, byte firstByte, byte secondByte, Encoding defaultEncoding)  
  39.          {  
  40.              int max = (int)Math.Min(fs.Length, 500000); // look at max. 500 KB  
  41.              const int ASCII = 0;  
  42.              const int Error = 1;  
  43.              const int UTF8 = 2;  
  44.              const int UTF8Sequence = 3;  
  45.              int state = ASCII;  
  46.              int sequenceLength = 0;  
  47.              byte b;  
  48.              for (int i = 0; i < max; i++)  
  49.              {  
  50.                  if (i == 0)  
  51.                  {  
  52.                      b = firstByte;  
  53.                  }  
  54.                  else if (i == 1)  
  55.                  {  
  56.                      b = secondByte;  
  57.                  }  
  58.                  else 
  59.                  {  
  60.                      b = (byte)fs.ReadByte();  
  61.                  }  
  62.                  if (b < 0x80)  
  63.                  {  
  64.                      // normal ASCII character  
  65.                      if (state == UTF8Sequence)  
  66.                      {  
  67.                          state = Error;  
  68.                          break;  
  69.                      }  
  70.                  }  
  71.                  else if (b < 0xc0)  
  72.                  {  
  73.                      // 10xxxxxx : continues UTF8 byte sequence  
  74.                      if (state == UTF8Sequence)  
  75.                      {  
  76.                          --sequenceLength;  
  77.                          if (sequenceLength < 0)  
  78.                          {  
  79.                              state = Error;  
  80.                              break;  
  81.                          }  
  82.                          else if (sequenceLength == 0)  
  83.                          {  
  84.                              state = UTF8;  
  85.                          }  
  86.                      }  
  87.                      else 
  88.                      {  
  89.                          state = Error;  
  90.                          break;  
  91.                      }  
  92.                  }  
  93.                  else if (b >= 0xc2 && b < 0xf5)  
  94.                  {  
  95.                      // beginning of byte sequence  
  96.                      if (state == UTF8 || state == ASCII)  
  97.                      {  
  98.                          state = UTF8Sequence;  
  99.                          if (b < 0xe0)  
  100.                          {  
  101.                              sequenceLength = 1; // one more byte following  
  102.                          }  
  103.                          else if (b < 0xf0)  
  104.                          {  
  105.                              sequenceLength = 2; // two more bytes following  
  106.                          }  
  107.                          else 
  108.                          {  
  109.                              sequenceLength = 3; // three more bytes following  
  110.                          }  
  111.                      }  
  112.                      else 
  113.                      {  
  114.                          state = Error;  
  115.                          break;  
  116.                      }  
  117.                  }  
  118.                  else 
  119.                  {  
  120.                      // 0xc0, 0xc1, 0xf5 to 0xff are invalid in UTF-8 (see RFC 3629)  
  121.                      state = Error;  
  122.                      break;  
  123.                  }  
  124.              }  
  125.              fs.Position = 0;  
  126.              switch (state)  
  127.              {  
  128.                  case ASCII:  
  129.                  case Error:  
  130.                      // when the file seems to be ASCII or non-UTF8,  
  131.                      // we read it using the user-specified encoding so it is saved again  
  132.                      // using that encoding.  
  133.                      if (IsUnicode(defaultEncoding))  
  134.                      {  
  135.                          // the file is not Unicode, so don't read it using Unicode even if the  
  136.                          // user has choosen Unicode as the default encoding.  
  137.    
  138.                          // If we don't do this, SD will end up always adding a Byte Order Mark  
  139.                          // to ASCII files.  
  140.                          defaultEncoding = Encoding.Default; // use system encoding instead  
  141.                      }  
  142.                      return new StreamReader(fs, defaultEncoding);  
  143.                  default:  
  144.                      return new StreamReader(fs);  
  145.              }  
  146.          } 

ITextSharp文件識(shí)別基本思路:

1.傳入需要讀取文件流,并且傳入一個(gè)你認(rèn)為合適的編碼方式,當(dāng)然你可以傳入NULL。

2.讀取文件前面2個(gè)字節(jié)(這個(gè)是大部分解析編碼需要做的事情),讀取進(jìn)來(lái)的字節(jié)向左移8位,然后與第二個(gè)字節(jié)進(jìn)行 | 運(yùn)算,主要用途是檢測(cè)StreamReader是否在iso - 8859 - 1和utf - 8之間的編碼范圍,并且不包含BOM。

忘記了C#這些運(yùn)算的可以看看,http://www.cnblogs.com/NatureSex/archive/2011/04/21/2023768.html

3.當(dāng)位移出來(lái)的結(jié)果等于0x0000,0xfffe,0xfeff,0xefbb時(shí),是StreamReader可以進(jìn)行自動(dòng)讀取范圍內(nèi)的。如果不在范圍內(nèi)時(shí)再進(jìn)行讀取偏移檢測(cè),具體怎么檢測(cè)的,這個(gè)有點(diǎn)難度,本人也只是看懂了一點(diǎn)點(diǎn),主要是系統(tǒng)編碼知識(shí)欠缺。

五.下載

下載地址:VS重命名工具   喜歡的朋友記得推薦一下喲

源碼就不放了,文件沒(méi)有混淆也沒(méi)有加密,自己反編譯統(tǒng)統(tǒng)都有。

原文鏈接:http://www.cnblogs.com/NatureSex/archive/2013/03/21/2971596.html

責(zé)任編輯:林師授 來(lái)源: 博客園
相關(guān)推薦

2010-11-19 13:48:18

2024-09-04 08:02:12

2021-10-09 07:52:01

Go程序重命名

2011-03-04 09:48:21

PureFTPd

2009-12-22 15:28:51

Linux批量重命名文

2018-06-25 13:10:16

Linux復(fù)制重命名

2010-09-13 13:33:51

sql server外

2011-12-22 10:08:56

塞班諾基亞Belle

2009-10-21 14:36:03

VB.NET批量重命名

2019-09-03 08:57:52

Linux命令軟件

2010-09-28 11:38:26

sql字段

2020-09-11 09:23:42

文件重命名Linux字符串

2021-01-31 18:51:11

移動(dòng)重命名Python

2020-06-09 07:42:30

重命名文件 Linux

2010-03-03 16:11:01

Linux ubant

2010-11-12 15:19:06

Sql Server外

2010-03-09 15:23:30

Linux批量重命名

2023-11-25 17:13:49

Linux重命名文件

2019-11-20 09:42:59

Windows 10重命名照片

2022-05-25 16:51:41

Git 分支重命名開(kāi)發(fā)者
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)