示例#1
0
        /// <summary>
        /// Get the T value(s) from the given set of Quads;
        /// Returns the original items.
        /// </summary>
        public static IReadOnlyList <Quad> Get <T>(this IEnumerable <Quad> self,
                                                   out T[] result) where T : notnull
        {
            TypeMustNotBeANode.Verify <T>();

            var ro = self.Ro();

            result = ro.Get <T>().ToArray();

            return(ro);
        }
示例#2
0
        /// <summary>Quads where Object is of Type</summary>
        /// <exception cref="TypeMustNotBeANode"></exception>
        public static IEnumerable <Quad> IsType <T1, T2>(this IEnumerable <Quad> self,
                                                         Func <Node, bool>?orPredicate = null)
            where T1 : notnull where T2 : notnull
        {
            TypeMustNotBeANode.Verify <T1>();
            TypeMustNotBeANode.Verify <T2>();

            return(self.Where(x => x.Object is Node <T1> ||
                              x.Object is Node <T2> ||
                              orPredicate != null && orPredicate(x.Object)));
        }
示例#3
0
        /// <inheritdoc />
        public Node <T> New <T>(T value) where T : notnull
        {
            TypeMustNotBeANode.Verify <T>();

            //Uri not supported.
            if (value is Uri)
            {
                throw new UriObjectNodeNotSupported();
            }

            //Try native object equality.
            var found = _nodes
                        .FirstOrDefault(x =>
                                        x is Node <T> v &&
                                        v.Value.Equals(value));

            if (found != null)
            {
                return((Node <T>)found);
            }

            //Find a Node map to use.
            var nodeMap = _nodeMaps
                          .OfType <NodeMap <T> >()
                          .FirstOrDefault(x => !(x is TypedLiteralMap)) ??
                          AddNodeType(new ObjectNodeMap <T>());

            //Create temporary.
            var tempNode = nodeMap.Create(value);

            //again try match
            if (tempNode.ValueString != null)
            {
                found = _nodes
                        .FirstOrDefault(x =>
                                        x.ValueType == tempNode.ValueType &&
                                        x.ValueStringHash == tempNode.ValueStringHash &&
                                        x.ValueString == tempNode.ValueString);

                if (found != null)
                {
                    return((Node <T>)found);
                }
            }

            //New
            _nodes.Add(tempNode);

            return(tempNode);
        }
示例#4
0
 /// <summary>Quads where Object value is of Type</summary>
 /// <exception cref="TypeMustNotBeANode"></exception>
 public static IEnumerable <Quad> IsType <T>(this IEnumerable <Quad> self, Func <Node, bool>?orPredicate = null)
     where T : notnull
 => TypeMustNotBeANode.Check <T>()?
 self.Where(x => x.Object is Node <T> ||
            orPredicate != null && orPredicate(x.Object)) :
 throw new TypeMustNotBeANode(typeof(T));
示例#5
0
 /// <summary>Get all values of type <typeparamref name="T"/>.</summary>
 /// <exception cref="TypeMustNotBeANode"></exception>
 public static T[] Get <T>(this IEnumerable <Quad> self)
     where T : notnull
 => TypeMustNotBeANode.Check <T>() ?
 self.Where(x => x.Object is Node <T>)
 .Select(x => ((Node <T>)x.Object).Value)
 .ToArray() : throw new TypeMustNotBeANode(typeof(T));
示例#6
0
 /// <summary>
 /// Try convert node to typed node.
 /// </summary>
 /// <exception cref="TypeMustNotBeANode"></exception>
 public static Node <T>?As <T>(this Node node) where T : notnull
 {
     TypeMustNotBeANode.Verify <T>();
     return(node as Node <T>);
 }