public virtual IFoxPropertyConverter MakePropertyConverter(Type targetType, IEntityReferenceResolver entityReferenceResolver) { var convertedList = Activator.CreateInstance(targetType) as IList; for (var i = 0; i < _values.Count; i++) { var value = _values[i]; if (value is IFoxReferenceType) { // Add null as a placeholder. // Replace it with the Entity reference once resolved. convertedList.Add(null); var iCopy = i; AssignReferenceDelegate referenceAssignmentDelegate = delegate(Entity reference) { convertedList[iCopy] = reference; }; entityReferenceResolver.RequestReference(referenceAssignmentDelegate, (value as IFoxReferenceType).ReferencedEntityAddress); } else if (value is IFoxValueType) { convertedList.Add((value as IFoxValueType).Unwrap()); } } return(new ValueTypeConverter(convertedList)); }
public void RequestReference(AssignReferenceDelegate referenceAssignmentDelegate, ulong referencedEntityAddress) { // If this address points to an Entity which has already been registered, assign the reference. Entity entityReference; if (registeredEntityTable.TryGetValue(referencedEntityAddress, out entityReference)) { referenceAssignmentDelegate.Invoke(entityReference); } // Otherwise, add a new entry to the entityRequestTable. else { // If there's already a set of requesters waiting for the same Entity, add the new requester to it. HashSet <AssignReferenceDelegate> requesters; if (entityRequestTable.TryGetValue(referencedEntityAddress, out requesters)) { requesters.Add(referenceAssignmentDelegate); } // If not, make a new set, add the requester to it, and add the set to the entityRequestTable. else { requesters = new HashSet <AssignReferenceDelegate> { referenceAssignmentDelegate }; entityRequestTable.Add(referencedEntityAddress, requesters); } } }
public IFoxPropertyConverter MakePropertyConverter(Type targetType, IEntityReferenceResolver entityReferenceResolver) { var convertedDictionary = Activator.CreateInstance(targetType) as IDictionary; foreach (var kvp in _map) { var value = kvp.Value; if (value is IFoxReferenceType) { // Add null as a placeholder. // Replace it with the Entity reference once resolved. convertedDictionary.Add(kvp.Key.Literal, null); var keyCopy = kvp.Key.Literal; AssignReferenceDelegate referenceAssignmentDelegate = delegate(Entity reference) { convertedDictionary[keyCopy] = reference; }; entityReferenceResolver.RequestReference(referenceAssignmentDelegate, (value as IFoxReferenceType).ReferencedEntityAddress); } else if (value is IFoxValueType) { convertedDictionary.Add(kvp.Key.Literal, (value as IFoxValueType).Unwrap()); } } return(new ValueTypeConverter(convertedDictionary)); }