网站页面设计说明书,redis 密码 wordpress,wordpress category.php制作,深圳市宝安区住房和建设局网站技巧1 自动生成带参构造函数当我们在编写代码时会经常遇到初始化一个的类#xff0c;需要通过构造函数进行对象初始化。那么这个时候我们可能会需要逐个去手动写#xff0c;这样的工作即重复又无趣。如果是在项目非常紧急的情况下还有大量的字段需要与入参一一对应起来简直太…技巧1 自动生成带参构造函数当我们在编写代码时会经常遇到初始化一个的类需要通过构造函数进行对象初始化。那么这个时候我们可能会需要逐个去手动写这样的工作即重复又无趣。如果是在项目非常紧急的情况下还有大量的字段需要与入参一一对应起来简直太要命了。大致情况如下public class Configinfo : Entity{public Configinfo() { }public Configinfo(int appType, string appName, string appSecretKey, string clientVersion, string updateUrl, string updateLogUrl, string installPath, string mainUpdateUrl, string mainAppName){AppType appType;AppName appName ?? throw new ArgumentNullException(nameof(appName));AppSecretKey appSecretKey ?? throw new ArgumentNullException(nameof(appSecretKey));ClientVersion clientVersion ?? throw new ArgumentNullException(nameof(clientVersion));UpdateUrl updateUrl ?? throw new ArgumentNullException(nameof(updateUrl));UpdateLogUrl updateLogUrl ?? throw new ArgumentNullException(nameof(updateLogUrl));InstallPath installPath ?? throw new ArgumentNullException(nameof(installPath));MainUpdateUrl mainUpdateUrl ?? throw new ArgumentNullException(nameof(mainUpdateUrl));MainAppName mainAppName ?? throw new ArgumentNullException(nameof(mainAppName));}/// summary/// 1:ClientApp 2:UpdateApp/// /summarypublic int AppType { get; set; }/// summary/// Need to start the name of the app./// /summarypublic string AppName { get; set; }/// summary/// application key/// /summarypublic string AppSecretKey { get; set; }/// summary/// Client current version./// /summarypublic string ClientVersion { get; set; }/// summary/// Update check api address./// /summarypublic string UpdateUrl { get; set; }/// summary/// Update log web address./// /summarypublic string UpdateLogUrl { get; set; }/// summary/// installation path (for update file logic)./// /summarypublic string InstallPath { get; set; }/// summary/// Update check api address./// /summarypublic string MainUpdateUrl { get; set; }public string MainAppName { get; set; }}看起来是不是非常头疼那么如何解决这个问题呢可以通过VisualStudio帮助开发者进行这重复的工作。空白处点击一下会出现一个小工具图标点击小工具选择生成构造函数。选择需要作为构造函数的参数生成代码如下public Configinfo(int appType, string appName, string appSecretKey, string clientVersion, string updateUrl, string updateLogUrl, string installPath, string mainUpdateUrl, string mainAppName){AppType appType;AppName appName ?? throw new ArgumentNullException(nameof(appName));AppSecretKey appSecretKey ?? throw new ArgumentNullException(nameof(appSecretKey));ClientVersion clientVersion ?? throw new ArgumentNullException(nameof(clientVersion));UpdateUrl updateUrl ?? throw new ArgumentNullException(nameof(updateUrl));UpdateLogUrl updateLogUrl ?? throw new ArgumentNullException(nameof(updateLogUrl));InstallPath installPath ?? throw new ArgumentNullException(nameof(installPath));MainUpdateUrl mainUpdateUrl ?? throw new ArgumentNullException(nameof(mainUpdateUrl));MainAppName mainAppName ?? throw new ArgumentNullException(nameof(mainAppName));}技巧2 Debug调试根据堆栈进行查找到代码调用在调式中我们通常都是按F10或者F11进行调试如果代码数量较少那么调试起来是非常简单的。如果代码多或者代码中方法内部不会集中很多其他的方法这时候我们往往会忘记上一步是由哪个地方跳转过来的从而导致我们晕头转向这个时候我们就需要利用VisualStudio中的堆栈信息进行辅助帮助我们思路清晰的查看代码的调用链路。示例代码如下internal class Class1{public void Test() {var local PublicMethod(new Juster(18));Console.WriteLine(local);}public static double PublicMethod(Juster juster) {double result GetScale(in juster);return result result;}private static double GetScale(in Juster input) input.Age * input.Age;}调用代码static void Main(string[] args){Class1 class1 new Class1();class1.Test();Console.WriteLine();}这个时候假设我们需要调试class1中的三个方法打上三个断点。这个时候我们运行到最后一个方法时假设代码内容非常复杂这个时候我们已经晕了。这时候就需要打开“堆栈调用”的窗口查看具体的调试信息。然后根据堆栈信息逐步往后看。我们从下往上逐步双击堆栈信息VisualStudio会自动帮助我们把关注点跳转到对应的代码行数也就是“发生地”。