Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
 public ReferenceTypeConverter(ulong referencedEntityAddress, IEntityReferenceResolver entityReferenceResolver)
 {
     entityReferenceResolver.RequestReference(AssignReference, referencedEntityAddress);
 }