C#常用代码片段备忘

2021-04-21 23:26

阅读:674

标签:win   move   sha   method   div   public   not   read   sig   

以下是从visual studio中整理出来的常用代码片段,以作备忘

快捷键: eh

用途: 类中事件实现函数模板

        private void MyMethod(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

快捷键: xmethod 有4个

用途: 类中公有静态方法的函数模板

        public static void MyMethod(this object value)
        {
            throw new NotImplementedException();
        }

快捷键: method 有4个

用途: 类中公有函数的模板

        public void MyMethod()
        {
            throw new NotImplementedException();
        }

快捷键: seh

用途: 类中私有静态方法的函数模板

        private static void MyMethod(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }   

快捷键: smethod 有4个

用途: 类中公有静态方法的函数模板

        public static void MyMethod()
        {
            throw new NotImplementedException();
        }

快捷键: vmethod 有4个

用途: 类中虚函数的模板

        public virtual void MyMethod()
        {
            throw new NotImplementedException();
        }

快捷键: propdp

用途: 定义依赖属性的模板

        public int MyProperty
        {
            get { return (int)GetValue(MyPropertyProperty); }
            set { SetValue(MyPropertyProperty, value); }
        }

        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MyPropertyProperty =
            DependencyProperty.Register("MyProperty", typeof(int), typeof(ownerclass), new PropertyMetadata(0));

快捷键: propa

用途: 定义附加属性的模板

        public static int GetMyProperty(DependencyObject obj)
        {
            return (int)obj.GetValue(MyPropertyProperty);
        }

        public static void SetMyProperty(DependencyObject obj, int value)
        {
            obj.SetValue(MyPropertyProperty, value);
        }

        // Using a DependencyProperty as the backing store for MyProperty.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty MyPropertyProperty =
            DependencyProperty.RegisterAttached("MyProperty", typeof(int), typeof(ownerclass), new PropertyMetadata(0));

快捷键: wde

用途: Windows工作流模式下创建依赖属性事件的模板

        public static System.Workflow.ComponentModel.DependencyProperty InvokeEvent = System.Workflow.ComponentModel.DependencyProperty.Register("Invoke", typeof(EventHandler), typeof(Obj));

        [System.ComponentModel.Description("Invoke")]
        [System.ComponentModel.Category("Invoke Category")]
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
        public event EventHandler Invoke
        {
            add
            {
                base.AddHandler(Obj.InvokeEvent, value);
            }
            remove
            {
                base.RemoveHandler(Obj.InvokeEvent, value);
            }
        }

快捷键: wdp

        public static System.Workflow.ComponentModel.DependencyProperty MyPropertyProperty = System.Workflow.ComponentModel.DependencyProperty.Register("MyProperty", typeof(string), typeof(Obj));

        [System.ComponentModel.Description("MyProperty")]
        [System.ComponentModel.Category("MyProperty Category")]
        [System.ComponentModel.Browsable(true)]
        [System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
        public string MyProperty
        {
            get
            {
                return ((string)(base.GetValue(Obj.MyPropertyProperty)));
            }
            set
            {
                base.SetValue(Obj.MyPropertyProperty, value);
            }
        }

快捷键: testc

用途: 新建一个C#的测试单元类的模板

        [Microsoft.VisualStudio.TestTools.UnitTesting.TestClass]
        public class MyTestClass
        {

        }

快捷键: testm

用途: 在C#的测试单元类中新增一个测试方法

        [TestMethod]
        public void MyTestMethod()
        {

        }   

C#常用代码片段备忘

标签:win   move   sha   method   div   public   not   read   sig   

原文地址:https://www.cnblogs.com/sanghg/p/8257024.html


评论


亲,登录后才可以留言!