William Basics

Keep learning, never ending.

[WPF] How to avoid calling initial methods in the view model’s constructor

Introduction When developing a WFP application in the MVVM way, we often need to initialize such as loading data, logging, and other kinds of stuff when the view model is created. The no-brain way is to call the “initialization” method directly in the view model’s constructor while hoping the calling method never fails and finishes instantly. public class AwsomeViewModel { public AwsomeViewModel () { LoadDataFromDatabase(); } } However, To call a method that is likely to fail or costs a long time is a bad practice in any way.

[Better code] - C# - Using Indexer

什么是Indexer? Indexer 可以帮助我们如同用索引来访问数组中的元素一样来访问自定义对象中的元素。它不仅可以帮助我们写出更流畅的代码,更提高了代

[UnitTest] - 用FluentAssertions让单元测试代码更优美

Introduction 早在2005年,Martin Fowler就提出了“fluent interface“这种编码风格(link)。我们比较熟悉的LINQ就是这”