Example #1
0
        private GraphNodePath PushElement(object elementValue, ElementType type)
        {
            var result = Clone(RootNode, false);

            switch (type)
            {
            case ElementType.Member:
                var name = elementValue as string;
                if (name == null)
                {
                    throw new ArgumentException("The value must be a non-null string when type is ElementType.Member.");
                }
                result.path.Add(NodePathElement.CreateMember(name));
                return(result);

            case ElementType.Target:
                if (elementValue != null)
                {
                    throw new ArgumentException("The value must be null when type is ElementType.Target.");
                }
                result.path.Add(NodePathElement.CreateTarget());
                return(result);

            case ElementType.Index:
                if (!(elementValue is Index))
                {
                    throw new ArgumentException("The value must be an Index when type is ElementType.Index.");
                }
                result.path.Add(NodePathElement.CreateIndex((Index)elementValue));
                return(result);

            default:
                throw new ArgumentOutOfRangeException(nameof(type));
            }
        }
Example #2
0
        private void PushElement(object elementValue, ElementType type)
        {
            switch (type)
            {
            case ElementType.Member:
                var name = elementValue as string;
                if (name == null)
                {
                    throw new ArgumentException("The value must be a non-null string when type is ElementType.Member.");
                }
                path.Add(NodePathElement.CreateMember(name));
                break;

            case ElementType.Target:
                if (elementValue != null)
                {
                    throw new ArgumentException("The value must be null when type is ElementType.Target.");
                }
                path.Add(NodePathElement.CreateTarget());
                break;

            case ElementType.Index:
                if (!(elementValue is NodeIndex))
                {
                    throw new ArgumentException("The value must be an Index when type is ElementType.Index.");
                }
                path.Add(NodePathElement.CreateIndex((NodeIndex)elementValue));
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(type));
            }
        }