星空网 > 软件开发 > ASP.net

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,那我们没必要在自己去浪费时间去了。

MethMVVM的安装:            

          使用之前,把这个扩展安装到Visual Studio中去,安装步骤如下:首先选择工具下面的扩展与安装

                           Visual Studio的MethMVVM

       

                        Visual Studio的MethMVVM

                在左边选择联系,在最右边搜索框中输入MethMVVM,点击搜索,会在中间的搜索结果框中显示所需的扩展方案,点击该搜索结果,安装完成后会自动重启Visual Studio,重启后就可以使用了!

MethMVVM的使用:

           meth-public method(公共方法)

           在Visual Studio的类中输入meth双击Tab显示代码为:

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

         methp-private method(私有方法),用法入meth一样。

         meth2-public method with two parameters(带两个参数的公共方法)

         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接口的通知事件

            Visual Studio的MethMVVM

        这个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的,大家都能够分享一下,都能从中受益。

        

     

   

 

 

  

  

 

 




原标题:Visual Studio的MethMVVM

关键词:Visual,Studio

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流