internal object SurrogateObjectIfNeeded(object o, int refId)
{
var surrogateId = surrogatesForObjects.FindMatchingIndex(o.GetType());
if(surrogateId != -1)
{
o = surrogatesForObjects.GetByIndex(surrogateId).DynamicInvoke(new[] { o });
// special case - surrogation!
// setting identifier for new object does not remove original one from the mapping
// thanks to that behaviour surrogation preserves identity
identifier.SetIdentifierForObject(o, refId);
}
return o;
}