public object[] GetSkipToken(IDataServiceQueryProvider dataServiceQueryPovider) { if (this.lastObject != null) { if (this.lastObject.GetType() == typeof(int)) { return(new object[] { -1 }); } object resource = this.lastObject; IExpandedResult expandedResult = resource as IExpandedResult; if (expandedResult != null) { resource = expandedResult.ExpandedElement; } IEnumerable <string> keyPropertyNames = this.IsReflectableResourceType ? new string[] { "ID" } : this.resourceType.KeyProperties.Select(property => property.Name); ProjectedWrapper projectedWrapper = resource as ProjectedWrapper; if (projectedWrapper != null) { return(keyPropertyNames.Select(propertyName => projectedWrapper.GetProjectedPropertyValue(propertyName)).ToArray()); } else if (dataServiceQueryPovider != null) { return(keyPropertyNames.Select(propertyName => dataServiceQueryPovider.GetPropertyValue(resource, this.resourceType.Properties.Single(p => p.Name == propertyName))).ToArray()); } else { return(keyPropertyNames.Select(propertyName => resource.GetType().GetProperty(propertyName).GetValue(resource, null)).ToArray()); } } return(new Random().Next() % 2 == 0 ? null : new object[0]); }
/// <summary>Adds a property to the null valued collection</summary> /// <param name="epmInfo">EpmInfo containing the property information such as path</param> internal void Add(EntityPropertyMappingInfo epmInfo) { Debug.Assert(epmInfo != null, "epmInfo != null"); EpmNullValuedPropertyNode current = this.root; ResourceType currentType = epmInfo.DefiningType; object currentValue = this.element; // We are here because the epm path points to a null value. If the path is multiple level deep, we need to // know the first level the null value begins and we don't need to serialize deeper than that. // To serialize the complex properties correctly in the case they are not already in content, we also need // to find the type for each segment from root to the first segment that has the null property value. foreach (var segment in epmInfo.Attribute.SourcePath.Split('/')) { EpmNullValuedPropertyNode child = current.Children.FirstOrDefault(c => c.Name == segment); if (child != null) { // The current segment is already added to the tree, reuse it. current = child; currentValue = child.Element; currentType = child.ResourceType; } else { EpmNullValuedPropertyNode newNode = new EpmNullValuedPropertyNode { Name = segment }; Debug.Assert(currentType != null, "currentType != null"); ResourceProperty property = currentType.TryResolvePropertyName(segment); Debug.Assert(currentValue != null, "currentValue != null"); ProjectedWrapper projectedValue = currentValue as ProjectedWrapper; if (projectedValue == null) { if (property != null) { currentValue = this.provider.GetPropertyValue(currentValue, property, currentType); currentValue = currentValue == DBNull.Value ? null : currentValue; currentType = property.ResourceType; } else { // Handle open property... currentValue = this.provider.GetOpenPropertyValue(currentValue, segment); currentValue = currentValue == DBNull.Value ? null : currentValue; if (currentValue != null) { // Get the type from the instance. currentType = this.provider.GetResourceType(currentValue); } else { // We have a null open property at hand, we don't know its type. // Default the type to string so that we will omit the type name // and just write out null. i.e. <d:prop m:null='true'/> currentType = ResourceType.PrimitiveStringResourceType; } } } else { currentValue = projectedValue.GetProjectedPropertyValue(segment); currentValue = currentValue == DBNull.Value ? null : currentValue; if (property != null) { currentType = property.ResourceType; } else { // Handle open property... if (currentValue == null) { // We have a null open property at hand, we don't know its type. // Default the type to string so that we will omit the type name // and just write out null. i.e. <d:prop m:null='true'/> currentType = ResourceType.PrimitiveStringResourceType; } else { projectedValue = currentValue as ProjectedWrapper; if (projectedValue != null) { // Get the type from the project wrapper. currentType = this.provider.TryResolveResourceType(projectedValue.ResourceTypeName); } else { // Get the type from the instance. currentType = this.provider.GetResourceType(currentValue); } } } } Debug.Assert(currentType != null, "currentType != null"); Debug.Assert(currentValue != DBNull.Value, "currentValue != DBNull.Value -- we have converted DBNull to null"); newNode.ResourceType = currentType; newNode.Element = currentValue; current.Children.Add(newNode); current = newNode; } if (current.Element == null) { // If the current element is null, we don't need to go further since that is the obvious reason // that the children properties are null. break; } } }