Each hierarchy should be registered to work correctly. In some cases (see Getting Started code sample), it is not needed to be register, but in most cases the registration is compulsory. The registration may be skipped only when all following requirements are fulfilled:
- No descendants of the object are supposed to support this particular structure,
- The object was not generated by means of Xafari.XF,
- The ParentAttribute and the ChildrenAttribute are declared straight in the class that demands the hierarchical structure to be implemented.
If all three conditions above are satisfied, the hierarchy is registered automatically. It is done this way to prevent possible errors of using metadata in the hierarchy logic.
It is recommended to always register hierarchies. Thus, the manual hierarchy registration is desirable even for the case described above.
The code below demonstrates how to register a hierarchy in the XafApplication.SetupComplete event handler:
void application_SetupComplete(object sender, EventArgs e)
//Use the method of the HierarchyManager class
HierarchyManager.Instance.RegisterHierarchy<ExampleIHierarchyNode>(hierarchyName: HierarchyManager.DefaultHierarchyName, parentMemberPath: "Parent", nodeNameMemberPath: "Name");
//It is also possible to use the extension methods of ITypesInfo
//The result will be the same
// hierarchyName: HierarchyManager.DefaultHierarchyName,
// parentMemberPath: "Parent",
// nodeNameMemberPath: "Name");
Private Sub application_SetupComplete(ByVal sender As Object, ByVal e As EventArgs)
'Use the method of the HierarchyManager class
HierarchyManager.Instance.RegisterHierarchy(Of ExampleIHierarchyNode)(hierarchyName := HierarchyManager.DefaultHierarchyName, parentMemberPath := "Parent", nodeNameMemberPath := "Name")
'It is also possible to use the extension methods of ITypesInfo
'The result will be the same
' hierarchyName: HierarchyManager.DefaultHierarchyName,
' parentMemberPath: "Parent",
' nodeNameMemberPath: "Name");
The parameters of the RegisterHierarchy method match the attributes declared in the Xafari.BC.HierarchicalData namespace.