意外丢失,很重要的内容全无,非常无语,草搞箱也不见了。现在快速恢复一些内容
EuropeanCastle.Books 类库,给所有书类添加了 BookBase基类
public abstract class BookBase : BindingableBase
{
private string name;
private Catalogue catalogue = new Catalogue();
protected BookBase()
{
}
public string Name
{
get { return name; }
set { SetProperty(ref name, value); }
}
public Catalogue Catalogue
{
get { return catalogue; }
set { SetProperty(ref catalogue, value); }
}
}
FrameworkDesignGuidelinesBook 类得到更新,添加了另一个内部类初始化这个类的目录信息,也继承了新类
public class FrameworkDesignGuidelinesBook : BookBase
{
private FrameworkDesignGuidelinesBookInitCatalogue initCatalogue = new FrameworkDesignGuidelinesBookInitCatalogue();
public FrameworkDesignGuidelinesBook()
{
Name = ".NET 设计规范约定、惯用法与模式(第二版)";
InitCatalogue();
}
public override string ToString()
{
return Name;
}
private void InitCatalogue()
{
Catalogue.Add(initCatalogue.NewChapterOne());
Catalogue.Add(initCatalogue.NewChapterTwo());
Catalogue.Add(initCatalogue.NewChapterThree());
Catalogue.Add(initCatalogue.NewChapterFour());
Catalogue.Add(initCatalogue.NewChapterFive());
Catalogue.Add(initCatalogue.NewChapterSix());
Catalogue.Add(initCatalogue.NewChapterSeven());
Catalogue.Add(initCatalogue.NewChapterEight());
Catalogue.Add(initCatalogue.NewChapterNine());
}
}
添加了 FrameworkDesignGuidelinesBookInitCatalogue 内部类
更新了 WpfProgrammingValuables2012Book 类
添加了绑定 BindingableBase 基类,所有类都继承了这个基类
public class BindingableBase : INotifyPropertyChanged
{
protected BindingableBase()
{
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(PropertyChangedEventArgs e)
{
var propertyChanded = PropertyChanged;
if (propertyChanded != null)
{
PropertyChanged(this, e);
}
}
protected void SetProperty<T>(ref T item, T value, [CallerMemberName]string propertyName = null)
{
if (!EqualityComparer<T>.Default.Equals(item, value))
{
item = value;
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
}
}
控制台项目也更新代码
static void Main(string[] args)
{
var frameDesGuidlinesBook = new FrameworkDesignGuidelinesBook();
foreach (var item in frameDesGuidlinesBook.Catalogue.GetEnumeratorTreeView())
{
Console.WriteLine(item);
}
Console.WriteLine();
Console.ReadLine();
}
输出有了层化,得益于 Catalogue 类添加了自定义迭代方法
public IEnumerable<string> GetEnumeratorTreeView()
{
foreach (var chapter in Items)
{
var paddingLeft = " ";//左填充
yield return chapter.ToString();//首层,章节
foreach (var section in chapter.Sections)
{
yield return paddingLeft + section.Name;//第二层
foreach (var nestSection in section.Sections)
{
yield return paddingLeft + paddingLeft + nestSection.Name;//第三层
}
}
}
}
输出结果
1万+

被折叠的 条评论
为什么被折叠?



