Show / Hide Table of Contents

Class Extensions

Provides useful Extension Methods for use elsewhere in the Library.

Inheritance
object
Extensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: VDS.RDF
Assembly: dotNetRdf.dll
Syntax
public static class Extensions

Methods

| Edit this page 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.

IEnumerable<INode> objects

Objects to add to the collection.

| Edit this page 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.

IEnumerable<T> objects

Objects to add to the collection.

Func<T, INode> mapFunc

Mapping from Object Type to INode.

Type Parameters
Name Description
T

Type of Objects.

| Edit this page View Source

AppendBlockIndented(StringBuilder, string, string, bool)

Append all of the lines in block to this StringBuilder with the specified indent as space characters.

Declaration
public static void AppendBlockIndented(this StringBuilder builder, string block, string indent, bool indentFirst = false)
Parameters
Type Name Description
StringBuilder builder

The StringBuilder to append the block to.

string block

The block to be appended.

string indent

The string to prepend to each indented line.

bool indentFirst

Whether to indent the first line of the block or not.

| Edit this page View Source

AppendIndented(StringBuilder, string, int)

Appends a String to the StringBuilder with an indent of indent spaces.

Declaration
public static void AppendIndented(this StringBuilder builder, string line, int indent)
Parameters
Type Name Description
StringBuilder builder

String Builder.

string line

String to append.

int indent

Indent.

| Edit this page View Source

AppendLineIndented(StringBuilder, string, int)

Appends a String to the StringBuilder with an indent of indent spaces.

Declaration
public static void AppendLineIndented(this StringBuilder builder, string line, int indent)
Parameters
Type Name Description
StringBuilder builder

String Builder.

string line

String to append.

int indent

Indent.

Remarks

Strings containing new lines are split over multiple lines.

| Edit this page 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
IEnumerable<T>
Type Parameters
Name Description
T

Type of the enumerable.

Remarks

This method taken from Stack Overflow - see. here

| Edit this page 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.

| Edit this page 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.

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.

| Edit this page 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.

IEnumerable<INode> objects

Objects to place in the collection.

| Edit this page 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.

IEnumerable<T> objects

Objects to place in the collection.

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.

| Edit this page 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.

IEnumerable<T> objects

Objects to place in the collection.

Func<T, INode> mapFunc

Mapping from Object Type to INode.

Type Parameters
Name Description
T

Type of Objects.

| Edit this page View Source

BlankNodes(IEnumerable<INode>)

Gets the Blank Nodes.

Declaration
public static IEnumerable<IBlankNode> BlankNodes(this IEnumerable<INode> ns)
Parameters
Type Name Description
IEnumerable<INode> ns

Nodes.

Returns
Type Description
IEnumerable<IBlankNode>
| Edit this page View Source

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

Splits a sequence into bounded chunks.

Declaration
public static IEnumerable<T[]> ChunkBy<T>(this IEnumerable<T> source, int size)
Parameters
Type Name Description
IEnumerable<T> source

An Enumerable.

int size

Max Chunk Size.

Returns
Type Description
IEnumerable<T[]>
Type Parameters
Name Description
T

Type Parameter.

| Edit this page View Source

EffectiveBooleanValue(INode)

Calculates the Effective Boolean Value of a given Node according to the Sparql specification.

Declaration
public static bool EffectiveBooleanValue(this INode n)
Parameters
Type Name Description
INode n

Node to computer EBV for.

Returns
Type Description
bool
| Edit this page View Source

GetEnhancedHashCode(Uri)

Gets an Enhanced Hash Code for a Uri.

Declaration
public static int GetEnhancedHashCode(this Uri u)
Parameters
Type Name Description
Uri u

Uri to get Hash Code for.

Returns
Type Description
int
Remarks

The .Net 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.

| Edit this page 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
IEnumerable<Triple>

Triples that make up the List.

| Edit this page 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
IEnumerable<INode>

Nodes that are the items in the list.

| Edit this page 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
IEnumerable<INode>

Nodes that are the intermediate nodes of the list.

| Edit this page View Source

GetSha256Hash(string)

Gets a SHA256 Hash for a String.

Declaration
public static string GetSha256Hash(this string s)
Parameters
Type Name Description
string s

String to hash.

Returns
Type Description
string
| Edit this page View Source

GetSha256Hash(Uri)

Gets an SHA256 Hash for a URI.

Declaration
public static string GetSha256Hash(this Uri u)
Parameters
Type Name Description
Uri u

URI to get Hash Code for.

Returns
Type Description
string
| Edit this page View Source

GraphLiteralNodes(IEnumerable<INode>)

Gets the Graph Literal Nodes.

Declaration
public static IEnumerable<IGraphLiteralNode> GraphLiteralNodes(this IEnumerable<INode> ns)
Parameters
Type Name Description
IEnumerable<INode> ns

Nodes.

Returns
Type Description
IEnumerable<IGraphLiteralNode>
| Edit this page View Source

IsAscii(string)

Determines whether a string is ASCII.

Declaration
public static bool IsAscii(this string value)
Parameters
Type Name Description
string value
Returns
Type Description
bool
| Edit this page 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
IEnumerable<T> x

An Enumerable.

IEnumerable<T> y

Another Enumerable.

Returns
Type Description
bool
Type Parameters
Name Description
T

Type Parameter.

| Edit this page 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
bool
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.

| Edit this page View Source

LiteralNodes(IEnumerable<INode>)

Gets the Literal Nodes.

Declaration
public static IEnumerable<ILiteralNode> LiteralNodes(this IEnumerable<INode> ns)
Parameters
Type Name Description
IEnumerable<INode> ns

Nodes.

Returns
Type Description
IEnumerable<ILiteralNode>
| Edit this page 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.

Dictionary<INode, INode> mapping

Mapping of Nodes.

Returns
Type Description
Triple
| Edit this page 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.

IEnumerable<INode> objects

Objects to remove from the collection.

| Edit this page 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.

IEnumerable<T> objects

Objects to remove from the collection.

Func<T, INode> mapFunc

Mapping from Object Type to INode.

Type Parameters
Name Description
T

Type of Objects.

| Edit this page 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.

| Edit this page 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.

| Edit this page View Source

ToSafeString(object)

Gets either the String representation of the Object or the Empty String if the object is null.

Declaration
public static string ToSafeString(this object obj)
Parameters
Type Name Description
object obj

Object.

Returns
Type Description
string
| Edit this page View Source

ToSafeString(Uri)

Gets either the String representation of the URI or the Empty String if the URI is null.

Declaration
public static string ToSafeString(this Uri u)
Parameters
Type Name Description
Uri u

URI.

Returns
Type Description
string
| Edit this page View Source

ToSafeUri(string, IUriFactory)

Turns a string into a safe URI.

Declaration
public static Uri ToSafeUri(this string str, IUriFactory uriFactory = null)
Parameters
Type Name Description
string str

String.

IUriFactory uriFactory

Factor to use when creating the URI. If not specified, the Root instance will be used.

Returns
Type Description
Uri

Either null if the string is null/empty or a URI otherwise.

| Edit this page 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
Uri u

URI.

IUriFormatter formatter

URI Formatter.

Returns
Type Description
string
| Edit this page View Source

UriNodes(IEnumerable<INode>)

Gets the URI Nodes.

Declaration
public static IEnumerable<IUriNode> UriNodes(this IEnumerable<INode> ns)
Parameters
Type Name Description
IEnumerable<INode> ns

Nodes.

Returns
Type Description
IEnumerable<IUriNode>
| Edit this page View Source

VariableNodes(IEnumerable<INode>)

Gets the Variable Nodes.

Declaration
public static IEnumerable<IVariableNode> VariableNodes(this IEnumerable<INode> ns)
Parameters
Type Name Description
IEnumerable<INode> ns

Nodes.

Returns
Type Description
IEnumerable<IVariableNode>
| Edit this page 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
IEnumerable<Triple> ts

Enumerable of Triples.

INode obj

Object to match.

Returns
Type Description
IEnumerable<Triple>
| Edit this page 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
IEnumerable<Triple> ts

Enumerable of Triples.

INode predicate

Predicate to match.

Returns
Type Description
IEnumerable<Triple>
| Edit this page 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
IEnumerable<Triple> ts

Enumerable of Triples.

INode subject

Subject to match.

Returns
Type Description
IEnumerable<Triple>
  • Edit this page
  • View Source
In this article
  • Methods
    • AddToList(IGraph, INode, IEnumerable<INode>)
    • AddToList<T>(IGraph, INode, IEnumerable<T>, Func<T, INode>)
    • AppendBlockIndented(StringBuilder, string, string, bool)
    • AppendIndented(StringBuilder, string, int)
    • AppendLineIndented(StringBuilder, string, int)
    • 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>, int)
    • EffectiveBooleanValue(INode)
    • GetEnhancedHashCode(Uri)
    • GetListAsTriples(IGraph, INode)
    • GetListItems(IGraph, INode)
    • GetListNodes(IGraph, INode)
    • GetSha256Hash(string)
    • GetSha256Hash(Uri)
    • GraphLiteralNodes(IEnumerable<INode>)
    • IsAscii(string)
    • IsDisjoint<T>(IEnumerable<T>, IEnumerable<T>)
    • 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)
    • ToSafeString(object)
    • ToSafeString(Uri)
    • ToSafeUri(string, IUriFactory)
    • 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