public void AddReference(ObjectReference reference) { references.Add(reference); }
public void RemoveReference(ObjectReference reference) { foreach (ObjectReference other in references) { if (other.ObjectId == reference.ObjectId && other.Property == reference.Property) { references.Remove(other); return; } } }
public void SetReference(string property, object value) { if (Mute) return; //drop old references object currentValue = null; properties.TryGetValue(property, out currentValue); if (currentValue is PersistentId) { PersistentId id = (PersistentId)currentValue; if (Context.IsLoaded(id.Id)) { IPersistentObject oldRef = Context.Get(id.Id); ObjectReference reference = new ObjectReference(); reference.Property = property; reference.ObjectId = target.Id; ((IPersistentObject)oldRef).RemoveReference(reference); } } //create new reference if (value is IPersistentObject) { ObjectReference reference = new ObjectReference(); reference.Property = property; reference.ObjectId = target.Id; ((IPersistentObject)value).AddReference(reference); PersistentId id = new PersistentId(); id.Id = ((IPersistentObject)value).Id; value = id; } properties[property] = value; }