如下是從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()
{
}