示例#1
0
 private static void ApplyLinkProperties(ClientTypeAnnotation actualType, MaterializerEntry entry)
 {
     if (entry.ShouldUpdateFromPayload)
     {
         foreach (ClientPropertyAnnotation annotation in from p in actualType.Properties()
                  where p.PropertyType == typeof(DataServiceStreamLink)
                  select p)
         {
             StreamDescriptor descriptor;
             string           propertyName = annotation.PropertyName;
             if (entry.EntityDescriptor.TryGetNamedStreamInfo(propertyName, out descriptor))
             {
                 annotation.SetValue(entry.ResolvedObject, descriptor.StreamLink, propertyName, true);
             }
         }
     }
 }
示例#2
0
        /// <summary>
        /// Materializes the link properties if any with the url in the response payload
        /// </summary>
        /// <param name="actualType">Actual client type that is getting materialized.</param>
        /// <param name="entry">MaterializerEntry instance containing all the links that came in the response.</param>
        private static void ApplyLinkProperties(
            ClientTypeAnnotation actualType,
            MaterializerEntry entry)
        {
            Debug.Assert(actualType != null, "actualType != null");
            Debug.Assert(entry.Entry != null, "entry != null");

            if (entry.ShouldUpdateFromPayload)
            {
                foreach (var linkProperty in actualType.Properties().Where(p => p.PropertyType == typeof(DataServiceStreamLink)))
                {
                    string           propertyName = linkProperty.PropertyName;
                    StreamDescriptor streamDescriptor;
                    if (entry.EntityDescriptor.TryGetNamedStreamInfo(propertyName, out streamDescriptor))
                    {
                        // At this time we have materialized the stream link onto the stream descriptor object
                        // we'll always make sure the stream link is the same instance on the entity and the descriptor
                        linkProperty.SetValue(entry.ResolvedObject, streamDescriptor.StreamLink, propertyName, true /*allowAdd*/);
                    }
                }
            }
        }
示例#3
0
        internal IEnumerable <ODataProperty> PopulateProperties(ClientTypeAnnotation type, object resource, List <object> visitedComplexTypeObjects)
        {
            List <ODataProperty> list = new List <ODataProperty>();

            foreach (ClientPropertyAnnotation annotation in from p in type.Properties()
                     orderby p.PropertyName
                     select p)
            {
                if (((!annotation.IsDictionary && (annotation != type.MediaDataMember)) && !annotation.IsStreamLinkProperty) && ((type.MediaDataMember == null) || (type.MediaDataMember.MimeTypeProperty != annotation)))
                {
                    object propertyValue = annotation.GetValue(resource);
                    if (annotation.IsKnownType)
                    {
                        ODataProperty item = new ODataProperty {
                            Name  = annotation.EdmProperty.Name,
                            Value = GetPrimitiveValue(propertyValue, annotation.PropertyType)
                        };
                        list.Add(item);
                    }
                    else if (annotation.IsPrimitiveOrComplexCollection)
                    {
                        ODataProperty property2 = new ODataProperty {
                            Name  = annotation.EdmProperty.Name,
                            Value = this.CreateODataCollectionPropertyValue(annotation, propertyValue, visitedComplexTypeObjects)
                        };
                        list.Add(property2);
                    }
                    else if (!annotation.IsEntityCollection && !ClientTypeUtil.TypeIsEntity(annotation.PropertyType, this.requestInfo.MaxProtocolVersion))
                    {
                        ODataProperty property3 = new ODataProperty {
                            Name  = annotation.EdmProperty.Name,
                            Value = this.CreateODataComplexPropertyValue(annotation, propertyValue, visitedComplexTypeObjects)
                        };
                        list.Add(property3);
                    }
                }
            }
            return(list);
        }