Visual Studio的MethMVVM

MethMVVM介紹: 

       Visual Studio Gallery是微軟針對VisualStudio擴展提供的一種解決方案,在Visual Studio Gallery你可以找到各類不一樣主題的解決方案,而MethMVVM就是一種擴展,這個擴展方案根據名字也能大致猜出來是爲了實現MVVM設定的,Visual Studio Gallery給出的定義爲:Snippet for method creaion and MVVM proprties.根據文檔解釋發現其實這就是Visual Studio 上的Code Snipper,咱們本身也能夠封裝,可是既然有人家已經針對MVVM模式擴展了這個Code Snipper,那咱們不必在本身去浪費時間去了。web

MethMVVM的安裝:             mvvm

          使用以前,把這個擴展安裝到Visual Studio中去,安裝步驟以下:首先選擇工具下面的擴展與安裝工具

                          

       

                       

                在左邊選擇聯繫,在最右邊搜索框中輸入MethMVVM,點擊搜索,會在中間的搜索結果框中顯示所需的擴展方案,點擊該搜索結果,安裝完成後會自動重啓Visual Studio,重啓後就可使用了!this

MethMVVM的使用:spa

           meth-public method(公共方法)3d

           在Visual Studio的類中輸入meth雙擊Tab顯示代碼爲:code

        public int MethodName()
        {
            throw new NotImplementedException();
        }

         methp-private method(私有方法),用法入meth同樣。orm

         meth2-public method with two parameters(帶兩個參數的公共方法)blog

         methp2-private method with two parameters(帶有兩個參數的私有方法)接口

         meths-public static method(靜態方法)

        meths2-public static method with two parameters(帶有兩個參數的靜態方法)

         propmvvm-mvvm property(可以實現綁定通知的屬性)

         propall-generate typical property definition  in C#(C#的徹底屬性寫法)

         安裝了MethMVVM的擴展多了的也就是方法的定義和propmvvm,至於徹底屬性是在Visual Studio的Code Snipper中自帶就有,而propmvvm的定義仍是須要本身實現INotifyPropertyChanged接口的通知事件

           

        這個OnPropertyChanged的方法還須要咱們本身手動去實現,這裏的實現感受有點雞肋了,實現入下

     public event PropertyChangedEventHandler PropertyChanged;
 
        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }

 

總結:

        其實這個MethMVVM實現功能有限,仍是做爲一個擴展放到Visual Studio Gallery中去,而且以一篇文章的形式作了一個講解,主要是由此可以瞭解Visual Studio中有不少現成的擴展,能夠很方便的讓咱們去調用,不須要咱們本身寫不少代碼去實現,而且擴展的源碼咱們也能夠在CodePlex去找到,若是有使用起來可以方便咱們Coding的,你們都可以分享一下,都能從中受益。

相關文章
相關標籤/搜索