[VS 2010]Generate From Usage
namespace Generate_From_Usage { class Person { } } Generate Property當物件的屬性不存在時,我們可透過Generate From Usage的Generate Property來替我們產生。 使用後,會幫我們產生對應的屬性 using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Generate_From_Usage { class Person { public string Name { get; set; } } } 若要產生靜態的屬性,我們可以透過"類別.屬性名稱"來作Generate Property 使用後,靜態的屬性就產生了 using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Generate_From_Usage { class Person { public string Name { get; set; } public static string StaticProperty { get; set; } } } Generate Field當物件的欄位不存在時,我們可透過Generate From Usage的Generate Field來替我們產生。 使用後,會幫我們產生對應的欄位 using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Generate_From_Usage { class Person { private string _name; public string Name { get{return _name;} set; } } } 若要產生靜態的欄位,我們可以像下圖這般作Generate Field 使用後,靜態的欄位就產生了 using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Generate_From_Usage { class Person { private string _name; private static string _staticField; public string Name { get{return _name;} set; }
public static string StaticProperty { get { return _staticField; } set; }
}
} 也可以透過"類別.欄位名稱"來作Generate Field 同樣的,我們也可以產生靜態的欄位,只是存取範圍不同而已。 using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Generate_From_Usage { class Person { private string _name; private static string _staticField; public static string StaticField; public string Name { get{return _name;} set; }
public static string StaticProperty { get { return _staticField; } set; }
}
} Generate Constructer當物件的建構子不存在時,我們可透過Generate From Usage的Generate Constructer來替我們產生。 使用後,會幫我們產生對應的建構子 using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Generate_From_Usage { class Person { private string Name; private int Yesr;
public Person(string Name, int Yesr)
{
// TODO: Complete member initialization
this.Name = Name;
this.Yesr = Yesr;
}
}
} Generate Method當物件的方法不存在時,我們可透過Generate From Usage的Generate Method來替我們產生。 使用後,會幫我們產生對應的方法 using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Generate_From_Usage { class Person { internal void SayHello() { throw new NotImplementedException(); } } } 若要產生靜態的方法,我們可以像下圖這般作Generate Method 使用後,靜態的方法就產生了 using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Generate_From_Usage { class Person { internal void SayHello() { throw new NotImplementedException(); }
internal static void StaticSayHello()
{
throw new NotImplementedException();
}
}
} LinkVS 2010 Generate From UsageGenerate From UsageWalkthrough: TDD Support with the Generate From Usage FeatureGenerate From Usage in Visual Studio 2010Walkthrough: TDD Support with the Generate From Usage Feature in VS 2010 (Lisa Feigenbaum)HDI Video: Generate from Usage in Visual Studio 2010 with Karen LiuHow Do I Use Generate from Usage in Visual Studio 2010?