最近我采用了一种方便的方法来确保树状结构成员知道他们的父节点:
private metaCollection<metaPage> _servicePages;
/// <summary>
/// Registry of service pages used by this document
/// </summary>
[Category("metaDocument")]
[DisplayName("servicePages")]
[Description("Registry of service pages used by this document")]
public metaCollection<metaPage> servicePages
{
get
{
if (_servicePages == null) {
_servicePages = new metaCollection<metaPage>();
_servicePages.parent = this;
}
return _servicePages;
}
}
(概念是在属性获取方法中为私有字段创建实例)
我很想知道这种模式是否有一些众所周知的名字?甚至更多:这种做法是否存在已知问题/不良影响?
谢谢!