public static ReferenceDescriptionCollection BrowseSuperTypes(Session session, NodeId typeId, bool throwOnError)
{
ReferenceDescriptionCollection supertypes = new ReferenceDescriptionCollection();
try
{
// find all of the children of the field.
BrowseDescription nodeToBrowse = new BrowseDescription();
nodeToBrowse.NodeId = typeId;
nodeToBrowse.BrowseDirection = BrowseDirection.Inverse;
nodeToBrowse.ReferenceTypeId = ReferenceTypeIds.HasSubtype;
nodeToBrowse.IncludeSubtypes = false; // more efficient to use IncludeSubtypes=False when possible.
nodeToBrowse.NodeClassMask = 0; // the HasSubtype reference already restricts the targets to Types.
nodeToBrowse.ResultMask = (uint)BrowseResultMask.All;
ReferenceDescriptionCollection references = Browse(session, nodeToBrowse, throwOnError);
while (references != null && references.Count > 0)
{
// should never be more than one supertype.
supertypes.Add(references[0]);
// only follow references within this server.
if (references[0].NodeId.IsAbsolute)
{
break;
}
// get the references for the next level up.
nodeToBrowse.NodeId = (NodeId)references[0].NodeId;
references = Browse(session, nodeToBrowse, throwOnError);
}
// return complete list.
return supertypes;
}
catch (Exception exception)
{
if (throwOnError)
{
throw new ServiceResultException(exception, StatusCodes.BadUnexpectedError);
}
return null;
}
}