/// <summary> /// Deactivates the entity by removing all referenced entities from all reference properties. /// </summary> public virtual void Deactivate() { foreach (PropertyInfo property in GetType().GetProperties()) { if (EntitiesUtilities.IsReference(GetType(), property)) { property.SetValue(this, null, null); } } }
public virtual void CopyTo(IEntity entity) { foreach (PropertyInfo property in entity.GetType().GetProperties()) { if (property.CanWrite) { object value = EntitiesUtilities.GetPropertyValue(this, property.Name); property.SetValue(entity, value, null); } } }
public virtual EntityReference SwitchFor(string typeName, Guid id) { //EntityReference reference = (EntityReference)Clone(); EntityReference reference = this; // TODO: Comment out logging to boost performance using (LogGroup logGroup = LogGroup.StartDebug("Switching reference data to the perspective of a '" + typeName + "' entity.")) { if (typeName == null) { throw new ArgumentNullException("typeName"); } LogWriter.Debug("Existing source entity type: " + Type1Name); LogWriter.Debug("Existing reference entity type: " + Type2Name); LogWriter.Debug("Existing source entity ID: " + Entity1ID.ToString()); LogWriter.Debug("Existing reference entity ID: " + Entity2ID.ToString()); LogWriter.Debug("Existing source property name: " + Property1Name.ToString()); LogWriter.Debug("Existing reference property name: " + Property2Name.ToString()); if (EntitiesUtilities.MatchAlias(typeName, Type1Name) && Entity1ID == id) { LogWriter.Debug("The reference is already in the perspective of the specified entity. No need to switch."); } else { LogWriter.Debug("Switching to the perspective of entity type: " + typeName); Guid entity1ID = Entity1ID; Guid entity2ID = Entity2ID; string type1Name = Type1Name; string type2Name = Type2Name; string property1Name = Property1Name; string property2Name = Property2Name; IEntity originalSourceEntity = SourceEntity; IEntity originalReferenceEntity = ReferenceEntity; reference.SourceEntity = originalReferenceEntity; reference.ReferenceEntity = originalSourceEntity; reference.Entity1ID = entity2ID; reference.Entity2ID = entity1ID; reference.Type1Name = type2Name; reference.Type2Name = type1Name; reference.Property1Name = property2Name; reference.Property2Name = property1Name; LogWriter.Debug("New source entity type: " + reference.Type1Name); LogWriter.Debug("New reference entity type: " + reference.Type2Name); LogWriter.Debug("New source entity ID: " + reference.Entity1ID.ToString()); LogWriter.Debug("New reference entity ID: " + reference.Entity2ID.ToString()); LogWriter.Debug("New source property name: " + reference.Property1Name.ToString()); LogWriter.Debug("New reference property name: " + reference.Property2Name.ToString()); } } return(reference); }