Example #1
0
        /// <summary>
        /// Creates an OData route from an ODCM node.
        /// </summary>
        /// <param name="node">The ODCM node</param>
        public ODataRoute(OdcmNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            // Store the node's ODCM property
            this.Property = node.OdcmProperty;

            // Store the parent node's ODCM property if it exists
            this.ParentProperty = node.Parent?.OdcmProperty;

            // Use a stack to add segments so we don't have to reverse them later
            Stack <OdcmProperty> segments = new Stack <OdcmProperty>();

            // Keep track of the ID parameters
            ICollection <string> idParameters = new List <string>();

            // Iterate over the node's parents (i.e. traverse the route in reverse)
            OdcmNode currentNode = node;
            OdcmNode childNode   = null;

            while (currentNode != null)
            {
                // Get the current node's property
                OdcmProperty property = currentNode.OdcmProperty;

                // Add this node to the route
                segments.Push(property);

                // Ignore this logic for the last segment in the route
                bool isLastSegment = childNode == null;
                if (!isLastSegment)
                {
                    // If the property this node represents is an enumeration, track its ID as a parameter
                    if (property.TryGetIdParameterName(out string idParameterName))
                    {
                        this._idParameters.Add(property, idParameterName);
                    }

                    // If the property's type is not the same as the class that the child property is defined in, the child class must be a subtype
                    if (property.Type != childNode.OdcmProperty.Class)
                    {
                        this._typeCastParameters.Add(property, property.GetResourceTypeParameterName());
                    }
                }

                // Update pointers
                childNode   = currentNode;
                currentNode = currentNode.Parent;
            }

            this.Segments = segments.ToList();
        }
Example #2
0
        /// <summary>
        /// Creates a child for this node.
        /// </summary>
        /// <param name="childData">The ODCM object to be used as the child</param>
        /// <returns>The created child node.</returns>
        public OdcmNode CreateChildNode(OdcmProperty childData)
        {
            if (childData == null)
            {
                throw new ArgumentNullException(nameof(childData));
            }

            OdcmNode childNode = new OdcmNode(this, childData);

            return(childNode);
        }
Example #3
0
 /// <summary>
 /// Creates an OdcmNode.
 /// </summary>
 /// <param name="parent">The parent node</param>
 /// <param name="odcmProperty">The ODCM object which this node represents</param>
 private OdcmNode(OdcmNode parent, OdcmProperty odcmProperty)
 {
     this.Parent       = parent ?? throw new ArgumentNullException(nameof(parent));
     this.OdcmProperty = odcmProperty ?? throw new ArgumentNullException(nameof(odcmProperty));
 }