Is it safe to store a reference to a document and access it later on?
public class Foo
{
public RhinoDoc Document { get; private set; }
public MyStore MyStore { get => Document.RuntimeData.GetValue(typeof(MyStore), rhinoDoc => new MyStore(rhinoDoc)); }
public Foo(RhinoDoc rhinoDoc) : base()
{
Document = rhinoDoc;
}
public void Bar() {
MyStore.Xyz();
}
}
Or should I always retrieve the document from the serialnumber?
public class Foo
{
public uint DocumentSerialNumber { get; private set; }
public RhinoDoc Document { get => RhinoDoc.FromRuntimeSerialNumber(DocumentSerialNumber); }
public MyStore MyStore { get => Document.RuntimeData.GetValue(typeof(MyStore), rhinoDoc => new MyStore(rhinoDoc)); }
public Foo(unit documentSerialNumber) : base()
{
DocumentSerialNumber = documentSerialNumber;
}
public void Bar() {
MyStore.Xyz();
}
}
What are the performance implications of each, if there are any? It seems expensive to look it up every time
It’s not. It’s the actual “user” controlled documents. Do you know if a reference to one of them will be valid as long as the user have that document open?