/// <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); }
/// <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))); }
/// <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); }
/// <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>); }