/// <summary>
        /// Deserializes the given <paramref name="link"/> under the given <paramref name="readContext"/>.
        /// </summary>
        /// <param name="link">The given delta link.</param>
        /// <param name="elementType">The element type.</param>
        /// <param name="readContext">The deserializer context.</param>
        /// <returns>The created object.</returns>
        public virtual object ReadDeltaLink(ODataDeltaLinkWrapper link, IEdmStructuredTypeReference elementType, ODataDeserializerContext readContext)
        {
            if (link == null)
            {
                throw Error.ArgumentNull(nameof(link));
            }

            if (readContext == null)
            {
                throw Error.ArgumentNull(nameof(readContext));
            }

            if (readContext.IsNoClrType)
            {
                EdmDeltaLink edmDeltaLink = new EdmDeltaLink(elementType?.Definition as IEdmEntityType);
                edmDeltaLink.Source       = link.DeltaLink.Source;
                edmDeltaLink.Target       = link.DeltaLink.Target;
                edmDeltaLink.Relationship = link.DeltaLink.Relationship;
                return(edmDeltaLink);
            }
            else
            {
                // refactor how to get the CLR type
                Type elementClrType = readContext.Model.GetClrType(elementType);

                Type       deltaLinkType = typeof(DeltaLink <>).MakeGenericType(elementClrType);
                IDeltaLink deltaLink     = Activator.CreateInstance(deltaLinkType) as IDeltaLink;

                deltaLink.Source       = link.DeltaLink.Source;
                deltaLink.Target       = link.DeltaLink.Target;
                deltaLink.Relationship = link.DeltaLink.Relationship;
                return(deltaLink);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///  Overwrites the <paramref name="originalSet"/> entity with the changes tracked by this Delta resource set.
        /// </summary>
        /// <param name="originalSet">The original set.</param>
        public virtual void Patch(IEnumerable <T> originalSet)
        {
            if (originalSet == null)
            {
                throw Error.ArgumentNull(nameof(originalSet));
            }

            // TODO: work out the patch process
            foreach (IDeltaItem delta in this)
            {
                T originalObj = GetOriginal(delta, originalSet);

                switch (delta.Kind)
                {
                case DeltaKind.DeltaResource:
                    // A Delta resource is a delta
                    IDelta deltaResource = (IDelta)delta;
                    break;

                case DeltaKind.DeltaDeletedResource:
                    // A Delta deleted resource is a delta deleted resource
                    IDeltaDeletedResource deltaDeletedResource = (IDeltaDeletedResource)delta;
                    break;

                case DeltaKind.DeltaDeletedLink:
                    IDeltaDeletedLink deltaDeletedLink = (IDeltaDeletedLink)delta;
                    break;

                case DeltaKind.DeltaLink:
                    IDeltaLink deltaLink = (IDeltaLink)delta;
                    break;

                case DeltaKind.Unknown:
                default:
                    //throw Error.InvalidOperation(SRResources.CannotSetDynamicPropertyDictionary, propertyInfo.Name,
                    //    entity.GetType().FullName);
                    throw Error.InvalidOperation("Unknow delta kind");
                }
            }
        }