示例#1
0
            /// <summary>Adds the null valued properties to the content section of a syndication entry</summary>
            /// <param name="currentRoot">Current root node</param>
            /// <param name="currentContent">Current collection to which property is to be added</param>
            private void AddNullValuesToContent(EpmNullValuedPropertyNode currentRoot, DictionaryContent currentContent)
            {
                foreach (EpmNullValuedPropertyNode node in currentRoot.Children)
                {
                    bool found;
                    DictionaryContent c = currentContent.Lookup(node.Name, out found);

                    Debug.Assert(node.ResourceType != null, "node.ResourceType != null");
                    switch (node.ResourceType.ResourceTypeKind)
                    {
                    case ResourceTypeKind.ComplexType:
                        if (!found)
                        {
                            // If a complex property is not found in content, it is either not being projected
                            // or all of its properties are mapped and all of them have KeepInContent=false
                            Debug.Assert(c == null, "when look up not found, c should be null.");
                            if (node.Element != null)
                            {
                                Debug.Assert(node.Children.Count > 0, "If the property represented by the current node is not null, there must be children nodes.");

                                // The complex property is not null, but some of its descendant properties are null.
                                // We need to serialize the type name of the complex property.
                                c = new DictionaryContent();
                                currentContent.Add(node.Name, node.ResourceType.FullName, c);
                            }
                            else
                            {
                                Debug.Assert(node.Children.Count == 0, "If the property represented by the current node is not null, there must not be any children node.");

                                // The complex property is null, we write out m:null='true'.
                                currentContent.AddNull(node.ResourceType.FullName, node.Name);
                            }
                        }

                        if (c != null)
                        {
                            // Only add the children properties if the complex property is not null.
                            this.AddNullValuesToContent(node, c);
                        }

                        break;

                    case ResourceTypeKind.Primitive:
                        Debug.Assert(c == null, "DictionaryContent not expected for primitive properties.");
                        Debug.Assert(node.Element == null, "node.Element == null");
                        if (!found)
                        {
                            currentContent.AddNull(node.ResourceType.FullName, node.Name);
                        }

                        // if found, use the value in currentContent, we don't need to do anything here.
                        break;

                    case ResourceTypeKind.EntityType:
                        Debug.Assert(false, "We cannot map navigation properties with friendly feeds.");
                        break;
                    }
                }
            }