Show / Hide Table of Contents

Class Extensions

Provides useful Extension Methods for use elsewhere in the Library.
Inheritance
System.Object
Extensions
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: VDS.RDF
Assembly: dotNetRDF.dll
Syntax
public static class Extensions

Methods

| Improve this Doc View Source

AddToList(IGraph, INode, IEnumerable<INode>)

Adds new items to the end of a list (aka a RDF collection).
Declaration
public static void AddToList(this IGraph g, INode listRoot, IEnumerable<INode> objects)
Parameters
Type Name Description
IGraph g Graph to assert in.
INode listRoot Root Node for the list.
System.Collections.Generic.IEnumerable<INode> objects Objects to add to the collection.
| Improve this Doc View Source

AddToList<T>(IGraph, INode, IEnumerable<T>, Func<T, INode>)

Adds new items to the end of a list (aka a RDF collection).
Declaration
public static void AddToList<T>(this IGraph g, INode listRoot, IEnumerable<T> objects, Func<T, INode> mapFunc)
Parameters
Type Name Description
IGraph g Graph to assert in.
INode listRoot Root Node for the list.
System.Collections.Generic.IEnumerable<T> objects Objects to add to the collection.
System.Func<T, INode> mapFunc Mapping from Object Type to INode.
Type Parameters
Name Description
T Type of Objects.
| Improve this Doc View Source

AsEnumerable<T>(T)

Takes a single item and generates an IEnumerable containing only it.
Declaration
public static IEnumerable<T> AsEnumerable<T>(this T item)
Parameters
Type Name Description
T item Item to wrap in an IEnumerable.
Returns
Type Description
System.Collections.Generic.IEnumerable<T>
Type Parameters
Name Description
T Type of the enumerable.
Remarks
This method taken from Stack Overflow - see. here
| Improve this Doc View Source

Assert(IGraph, INode, INode, INode)

Asserts a new Triple in the Graph.
Declaration
public static void Assert(this IGraph g, INode subj, INode pred, INode obj)
Parameters
Type Name Description
IGraph g Graph to assert in.
INode subj Subject.
INode pred Predicate.
INode obj Object.
Remarks
Handy method which means you can assert a Triple by specifying the Subject, Predicate and Object without having to explicity declare a new Triple.
| Improve this Doc View Source

AssertList(IGraph, IEnumerable<INode>)

Asserts a list as a RDF collection and returns the node that represents the root of the RDF collection.
Declaration
public static INode AssertList(this IGraph g, IEnumerable<INode> objects)
Parameters
Type Name Description
IGraph g Graph to assert in.
System.Collections.Generic.IEnumerable<INode> objects Objects to place in the collection.
Returns
Type Description
INode Either the blank node which is the root of the collection or rdf:nil for empty collections.
| Improve this Doc View Source

AssertList(IGraph, INode, IEnumerable<INode>)

Asserts a list as a RDF collection using an existing node as the list root.
Declaration
public static void AssertList(this IGraph g, INode listRoot, IEnumerable<INode> objects)
Parameters
Type Name Description
IGraph g Graph to assert in.
INode listRoot Root Node for List.
System.Collections.Generic.IEnumerable<INode> objects Objects to place in the collection.
| Improve this Doc View Source

AssertList<T>(IGraph, IEnumerable<T>, Func<T, INode>)

Asserts a list as a RDF collection and returns the node that represents the root of the RDF collection.
Declaration
public static INode AssertList<T>(this IGraph g, IEnumerable<T> objects, Func<T, INode> mapFunc)
Parameters
Type Name Description
IGraph g Graph to assert in.
System.Collections.Generic.IEnumerable<T> objects Objects to place in the collection.
System.Func<T, INode> mapFunc Mapping from Object Type to INode.
Returns
Type Description
INode Either the blank node which is the root of the collection or rdf:nil for empty collections.
Type Parameters
Name Description
T Type of Objects.
| Improve this Doc View Source

AssertList<T>(IGraph, INode, IEnumerable<T>, Func<T, INode>)

Asserts a list as a RDF collection using an existing node as the list root.
Declaration
public static void AssertList<T>(this IGraph g, INode listRoot, IEnumerable<T> objects, Func<T, INode> mapFunc)
Parameters
Type Name Description
IGraph g Graph to assert in.
INode listRoot Root Node for List.
System.Collections.Generic.IEnumerable<T> objects Objects to place in the collection.
System.Func<T, INode> mapFunc Mapping from Object Type to INode.
Type Parameters
Name Description
T Type of Objects.
| Improve this Doc View Source

BlankNodes(IEnumerable<INode>)

Gets the Blank Nodes.
Declaration
public static IEnumerable<IBlankNode> BlankNodes(this IEnumerable<INode> ns)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<INode> ns Nodes.
Returns
Type Description
System.Collections.Generic.IEnumerable<IBlankNode>
| Improve this Doc View Source

ChunkBy<T>(IEnumerable<T>, Int32)

Splits a sequence into bounded chunks.
Declaration
public static IEnumerable<T[]> ChunkBy<T>(this IEnumerable<T> source, int size)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> source An Enumerable.
System.Int32 size Max Chunk Size.
Returns
Type Description
System.Collections.Generic.IEnumerable<T[]>
Type Parameters
Name Description
T Type Parameter.
| Improve this Doc View Source

CopyNode(INode, IGraph)

Copies a Node to the target Graph.
Declaration
public static INode CopyNode(this INode n, IGraph target)
Parameters
Type Name Description
INode n Node to copy.
IGraph target Target Graph.
Returns
Type Description
INode
Remarks
Shorthand for the CopyNode(INode, IGraph) method.
| Improve this Doc View Source

CopyNode(INode, IGraph, Boolean)

Copies a Node to the target Graph.
Declaration
public static INode CopyNode(this INode n, IGraph target, bool keepOriginalGraphUri)
Parameters
Type Name Description
INode n Node to copy.
IGraph target Target Graph.
System.Boolean keepOriginalGraphUri Indicates whether Nodes should preserve the Graph Uri of the Graph they originated from.
Returns
Type Description
INode
Remarks
Shorthand for the CopyNode(INode, IGraph, Boolean) method.
| Improve this Doc View Source

CopyTriple(Triple, IGraph)

Copies a Triple to the target Graph.
Declaration
public static Triple CopyTriple(this Triple t, IGraph target)
Parameters
Type Name Description
Triple t Triple to copy.
IGraph target Target Graph.
Returns
Type Description
Triple
Remarks
Shorthand for the CopyTriple(Triple, IGraph) method.
| Improve this Doc View Source

CopyTriple(Triple, IGraph, Boolean)

Copies a Triple to the target Graph.
Declaration
public static Triple CopyTriple(this Triple t, IGraph target, bool keepOriginalGraphUri)
Parameters
Type Name Description
Triple t Triple to copy.
IGraph target Target Graph.
System.Boolean keepOriginalGraphUri Indicates whether Nodes should preserve the Graph Uri of the Graph they originated from.
Returns
Type Description
Triple
Remarks
Shorthand for the CopyTriple(Triple, IGraph, Boolean) method.
| Improve this Doc View Source

Escape(String, Char)

Escapes all occurrences of a given character in a String.
Declaration
[Obsolete("No longer necessary, do not use", true)]
public static string Escape(this string value, char toEscape)
Parameters
Type Name Description
System.String value String.
System.Char toEscape Character to escape.
Returns
Type Description
System.String
Remarks
Ignores all existing escapes (indicated by a \) and so avoids double escaping as far as possible.
| Improve this Doc View Source

Escape(String, Char, Char)

Escapes all occurrences of a given character in a String using the given escape character.
Declaration
[Obsolete("No longer necessary, do not use", true)]
public static string Escape(this string value, char toEscape, char escapeAs)
Parameters
Type Name Description
System.String value String.
System.Char toEscape Character to escape.
System.Char escapeAs Character to escape as.
Returns
Type Description
System.String
Remarks
Ignores all existing escapes (indicated by a \) and so avoids double escaping as far as possible.
| Improve this Doc View Source

EscapeBackslashes(String, Char[])

Takes a String and escapes any backslashes in it which are not followed by a valid escape character.
Declaration
[Obsolete("No longer necessary, do not use", true)]
public static string EscapeBackslashes(this string value, char[] cs)
Parameters
Type Name Description
System.String value String value.
System.Char[] cs Valid Escape Characters i.e. characters which may follow a backslash.
Returns
Type Description
System.String
| Improve this Doc View Source

GetEnhancedHashCode(Uri)

Gets an Enhanced Hash Code for a Uri.
Declaration
public static int GetEnhancedHashCode(this Uri u)
Parameters
Type Name Description
System.Uri u Uri to get Hash Code for.
Returns
Type Description
System.Int32
Remarks
The .Net System.Uri class Hash Code ignores the Fragment ID when computing the Hash Code which means that URIs with the same basic URI but different Fragment IDs have identical Hash Codes. This is perfectly acceptable and sensible behaviour for normal URI usage since Fragment IDs are only relevant to the Client and not the Server. But in the case of URIs in RDF the Fragment ID is significant and so we need in some circumstances to compute a Hash Code which includes this information.
| Improve this Doc View Source

GetListAsTriples(IGraph, INode)

Gets all the Triples that make up a list (aka a RDF collection).
Declaration
public static IEnumerable<Triple> GetListAsTriples(this IGraph g, INode listRoot)
Parameters
Type Name Description
IGraph g Graph.
INode listRoot Root Node for List.
Returns
Type Description
System.Collections.Generic.IEnumerable<Triple> Triples that make up the List.
| Improve this Doc View Source

GetListItems(IGraph, INode)

Gets all the Nodes which are the items of the list (aka the RDF collection).
Declaration
public static IEnumerable<INode> GetListItems(this IGraph g, INode listRoot)
Parameters
Type Name Description
IGraph g Graph.
INode listRoot Root Node for List.
Returns
Type Description
System.Collections.Generic.IEnumerable<INode> Nodes that are the items in the list.
| Improve this Doc View Source

GetListNodes(IGraph, INode)

Gets all the Nodes which are the intermediate nodes in the list (aka the RDF collection). These represents the nodes used to link the actual items of the list together rather than the actual items of the list.
Declaration
public static IEnumerable<INode> GetListNodes(this IGraph g, INode listRoot)
Parameters
Type Name Description
IGraph g Graph.
INode listRoot Root Node for List.
Returns
Type Description
System.Collections.Generic.IEnumerable<INode> Nodes that are the intermediate nodes of the list.
| Improve this Doc View Source

GetSha256Hash(Uri)

Gets an SHA256 Hash for a URI.
Declaration
public static string GetSha256Hash(this Uri u)
Parameters
Type Name Description
System.Uri u URI to get Hash Code for.
Returns
Type Description
System.String
| Improve this Doc View Source

GraphLiteralNodes(IEnumerable<INode>)

Gets the Graph Literal Nodes.
Declaration
public static IEnumerable<IGraphLiteralNode> GraphLiteralNodes(this IEnumerable<INode> ns)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<INode> ns Nodes.
Returns
Type Description
System.Collections.Generic.IEnumerable<IGraphLiteralNode>
| Improve this Doc View Source

IsAscii(String)

Determines whether a string is ASCII.
Declaration
public static bool IsAscii(this string value)
Parameters
Type Name Description
System.String value
Returns
Type Description
System.Boolean
| Improve this Doc View Source

IsDisjoint<T>(IEnumerable<T>, IEnumerable<T>)

Determines whether the contents of two enumerables are disjoint.
Declaration
public static bool IsDisjoint<T>(this IEnumerable<T> x, IEnumerable<T> y)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<T> x An Enumerable.
System.Collections.Generic.IEnumerable<T> y Another Enumerable.
Returns
Type Description
System.Boolean
Type Parameters
Name Description
T Type Parameter.
| Improve this Doc View Source

IsFullyEscaped(String, Char[], Char[])

Determines whether a String is fully escaped.
Declaration
[Obsolete("No longer necessary, do not use", true)]
public static bool IsFullyEscaped(this string value, char[] cs, char[] ds)
Parameters
Type Name Description
System.String value String value.
System.Char[] cs Valid Escape Characters i.e. characters which may follow a backslash.
System.Char[] ds Characters which must be escaped i.e. must be preceded by a backslash.
Returns
Type Description
System.Boolean
| Improve this Doc View Source

IsListRoot(INode, IGraph)

Gets whether a given Node is valid as a List Root, this does not guarantee that the list itself is valid simply that the Node appears to be the root of a list.
Declaration
public static bool IsListRoot(this INode n, IGraph g)
Parameters
Type Name Description
INode n Node to check.
IGraph g Graph.
Returns
Type Description
System.Boolean
Remarks
We consider a node to be a list root if there are no incoming rdf:rest triples and only a single outgoing rdf:first triple.
| Improve this Doc View Source

LiteralNodes(IEnumerable<INode>)

Gets the Literal Nodes.
Declaration
public static IEnumerable<ILiteralNode> LiteralNodes(this IEnumerable<INode> ns)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<INode> ns Nodes.
Returns
Type Description
System.Collections.Generic.IEnumerable<ILiteralNode>
| Improve this Doc View Source

MapTriple(Triple, IGraph, Dictionary<INode, INode>)

Copies a Triple from one Graph mapping Nodes as appropriate.
Declaration
public static Triple MapTriple(this Triple t, IGraph target, Dictionary<INode, INode> mapping)
Parameters
Type Name Description
Triple t Triple to copy.
IGraph target TargetGraph.
System.Collections.Generic.Dictionary<INode, INode> mapping Mapping of Nodes.
Returns
Type Description
Triple
| Improve this Doc View Source

RemoveFromList(IGraph, INode, IEnumerable<INode>)

Removes the given items from a list (aka a RDF collection), if an item occurs multiple times in the list all occurrences will be removed.
Declaration
public static void RemoveFromList(this IGraph g, INode listRoot, IEnumerable<INode> objects)
Parameters
Type Name Description
IGraph g Graph to retract from.
INode listRoot Root Node for the list.
System.Collections.Generic.IEnumerable<INode> objects Objects to remove from the collection.
| Improve this Doc View Source

RemoveFromList<T>(IGraph, INode, IEnumerable<T>, Func<T, INode>)

Removes the given items from a list (aka a RDF collection), if an item occurs multiple times in the list all occurrences will be removed.
Declaration
public static void RemoveFromList<T>(this IGraph g, INode listRoot, IEnumerable<T> objects, Func<T, INode> mapFunc)
Parameters
Type Name Description
IGraph g Graph to retract from.
INode listRoot Root Node for the list.
System.Collections.Generic.IEnumerable<T> objects Objects to remove from the collection.
System.Func<T, INode> mapFunc Mapping from Object Type to INode.
Type Parameters
Name Description
T Type of Objects.
| Improve this Doc View Source

Retract(IGraph, INode, INode, INode)

Retracts a Triple from the Graph.
Declaration
public static void Retract(this IGraph g, INode subj, INode pred, INode obj)
Parameters
Type Name Description
IGraph g Graph to retract from.
INode subj Subject.
INode pred Predicate.
INode obj Object.
Remarks
Handy method which means you can retract a Triple by specifying the Subject, Predicate and Object without having to explicity declare a new Triple.
| Improve this Doc View Source

RetractList(IGraph, INode)

Retracts a List (aka a RDF collection).
Declaration
public static void RetractList(this IGraph g, INode listRoot)
Parameters
Type Name Description
IGraph g Graph.
INode listRoot Root Node for List.
| Improve this Doc View Source

ToString(Uri, IUriFormatter)

Gets the String representation of the URI formatted using the given Formatter.
Declaration
public static string ToString(this Uri u, IUriFormatter formatter)
Parameters
Type Name Description
System.Uri u URI.
IUriFormatter formatter URI Formatter.
Returns
Type Description
System.String
| Improve this Doc View Source

UriNodes(IEnumerable<INode>)

Gets the URI Nodes.
Declaration
public static IEnumerable<IUriNode> UriNodes(this IEnumerable<INode> ns)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<INode> ns Nodes.
Returns
Type Description
System.Collections.Generic.IEnumerable<IUriNode>
| Improve this Doc View Source

VariableNodes(IEnumerable<INode>)

Gets the Variable Nodes.
Declaration
public static IEnumerable<IVariableNode> VariableNodes(this IEnumerable<INode> ns)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<INode> ns Nodes.
Returns
Type Description
System.Collections.Generic.IEnumerable<IVariableNode>
| Improve this Doc View Source

WithObject(IEnumerable<Triple>, INode)

Gets the Subset of Triples from an existing Enumerable that have a given Object.
Declaration
public static IEnumerable<Triple> WithObject(this IEnumerable<Triple> ts, INode obj)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Triple> ts Enumerable of Triples.
INode obj Object to match.
Returns
Type Description
System.Collections.Generic.IEnumerable<Triple>
| Improve this Doc View Source

WithPredicate(IEnumerable<Triple>, INode)

Gets the Subset of Triples from an existing Enumerable that have a given Predicate.
Declaration
public static IEnumerable<Triple> WithPredicate(this IEnumerable<Triple> ts, INode predicate)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Triple> ts Enumerable of Triples.
INode predicate Predicate to match.
Returns
Type Description
System.Collections.Generic.IEnumerable<Triple>
| Improve this Doc View Source

WithSubject(IEnumerable<Triple>, INode)

Gets the Subset of Triples from an existing Enumerable that have a given Subject.
Declaration
public static IEnumerable<Triple> WithSubject(this IEnumerable<Triple> ts, INode subject)
Parameters
Type Name Description
System.Collections.Generic.IEnumerable<Triple> ts Enumerable of Triples.
INode subject Subject to match.
Returns
Type Description
System.Collections.Generic.IEnumerable<Triple>
  • Improve this Doc
  • View Source
In This Article
  • Methods
    • AddToList(IGraph, INode, IEnumerable<INode>)
    • AddToList<T>(IGraph, INode, IEnumerable<T>, Func<T, INode>)
    • AsEnumerable<T>(T)
    • Assert(IGraph, INode, INode, INode)
    • AssertList(IGraph, IEnumerable<INode>)
    • AssertList(IGraph, INode, IEnumerable<INode>)
    • AssertList<T>(IGraph, IEnumerable<T>, Func<T, INode>)
    • AssertList<T>(IGraph, INode, IEnumerable<T>, Func<T, INode>)
    • BlankNodes(IEnumerable<INode>)
    • ChunkBy<T>(IEnumerable<T>, Int32)
    • CopyNode(INode, IGraph)
    • CopyNode(INode, IGraph, Boolean)
    • CopyTriple(Triple, IGraph)
    • CopyTriple(Triple, IGraph, Boolean)
    • Escape(String, Char)
    • Escape(String, Char, Char)
    • EscapeBackslashes(String, Char[])
    • GetEnhancedHashCode(Uri)
    • GetListAsTriples(IGraph, INode)
    • GetListItems(IGraph, INode)
    • GetListNodes(IGraph, INode)
    • GetSha256Hash(Uri)
    • GraphLiteralNodes(IEnumerable<INode>)
    • IsAscii(String)
    • IsDisjoint<T>(IEnumerable<T>, IEnumerable<T>)
    • IsFullyEscaped(String, Char[], Char[])
    • IsListRoot(INode, IGraph)
    • LiteralNodes(IEnumerable<INode>)
    • MapTriple(Triple, IGraph, Dictionary<INode, INode>)
    • RemoveFromList(IGraph, INode, IEnumerable<INode>)
    • RemoveFromList<T>(IGraph, INode, IEnumerable<T>, Func<T, INode>)
    • Retract(IGraph, INode, INode, INode)
    • RetractList(IGraph, INode)
    • ToString(Uri, IUriFormatter)
    • UriNodes(IEnumerable<INode>)
    • VariableNodes(IEnumerable<INode>)
    • WithObject(IEnumerable<Triple>, INode)
    • WithPredicate(IEnumerable<Triple>, INode)
    • WithSubject(IEnumerable<Triple>, INode)
Back to top Generated by DocFX