public ILocalNode ReferenceSharedNode(
ILocalNode source,
NodeId referenceTypeId,
bool isInverse,
QualifiedName browseName)
{
try
{
m_lock.Enter();
// find the instance declaration identified bt the browse name.
ILocalNode target = FindInstanceDeclaration(source, browseName);
if (target == null)
{
return null;
}
// find the references to the model parent for the instance declaration.
ExpandedNodeId parentId = target.References.FindTarget(ReferenceTypeIds.HasModelParent, false, false, null, 0);
if (!NodeId.IsNull(parentId))
{
IList<IReference> references = target.References.FindReferencesToTarget(parentId);
foreach (IReference reference in references)
{
if (reference.ReferenceTypeId == ReferenceTypeIds.HasModelParent)
{
continue;
}
source.References.Add(reference.ReferenceTypeId, !reference.IsInverse, target.NodeId);
target.References.Add(reference.ReferenceTypeId, reference.IsInverse, source.NodeId);
}
}
// add basic reference.
source.References.Add(referenceTypeId, isInverse, target.NodeId);
target.References.Add(referenceTypeId, !isInverse, source.NodeId);
// return child.
return target;
}
finally
{
m_lock.Exit();
}
}