Skip to content

Commit

Permalink
Apply quality suggestions from ReSharper
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco De Salvo committed Feb 17, 2025
1 parent 6c00ded commit 7c7fa32
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 52 deletions.
14 changes: 2 additions & 12 deletions RDFSharp/Model/Serializers/RDFTriX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,32 +214,23 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext)
if (trixDoc.DocumentElement != null)
{
#region Guards

if (!trixDoc.DocumentElement.Name.Equals("TriX")
|| !trixDoc.DocumentElement.NamespaceURI.Equals("http://www.w3.org/2004/03/trix/trix-1/"))
throw new Exception(" given file does not encode a TriX graph.");

if (trixDoc.DocumentElement.ChildNodes.Count > 1)
throw new Exception(" given TriX file seems to encode more than one graph.");

#endregion Guards

Dictionary<string, long> hashContext = new Dictionary<string, long>();
IEnumerator graphEnum = trixDoc.DocumentElement.ChildNodes.GetEnumerator();
while (graphEnum != null && graphEnum.MoveNext())
foreach (XmlNode graph in trixDoc.DocumentElement.ChildNodes)
{
XmlNode graph = (XmlNode)graphEnum.Current;
if (!graph.Name.Equals("graph", StringComparison.Ordinal))
throw new Exception(" a \"<graph>\" element was expected, instead of unrecognized \"<" + graph.Name + ">\".");

#region <graph>

long encodedUris = 0;
IEnumerator graphChildren = graph.ChildNodes.GetEnumerator();
while (graphChildren != null && graphChildren.MoveNext())
foreach (XmlNode graphChild in graph.ChildNodes)
{
XmlNode graphChild = (XmlNode)graphChildren.Current;

#region <uri>

//<uri> gives the context of the graph
Expand Down Expand Up @@ -267,7 +258,6 @@ internal static RDFGraph Deserialize(Stream inputStream, Uri graphContext)

#endregion <triple>
}

#endregion <graph>
}
}
Expand Down
19 changes: 4 additions & 15 deletions RDFSharp/Model/Serializers/RDFXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,13 +448,9 @@ private static List<RDFResource> ParseNodeList(XmlNodeList nodeList, RDFGraph re
Dictionary<string, long> hashContext, RDFResource subjectParent = null)
{
List<RDFResource> subjects = new List<RDFResource>();
IEnumerator subjNodesEnum = nodeList.GetEnumerator();
while (subjNodesEnum != null && subjNodesEnum.MoveNext())
foreach (XmlNode subjNode in nodeList)
{
#region subject
//Get the current resource node
XmlNode subjNode = (XmlNode)subjNodesEnum.Current;

//Skip subject if it is not an element
if (subjNode.NodeType != XmlNodeType.Element)
continue;
Expand Down Expand Up @@ -509,19 +505,15 @@ private static List<RDFResource> ParseNodeList(XmlNodeList nodeList, RDFGraph re
//Parse subject children (predicates)
if (subjNode.HasChildNodes)
{
IEnumerator predNodesEnum = subjNode.ChildNodes.GetEnumerator();
while (predNodesEnum != null && predNodesEnum.MoveNext())
foreach (XmlNode predNode in subjNode.ChildNodes)
{
#region predicate
//Get the current pred node
RDFResource pred;
XmlNode predNode = (XmlNode)predNodesEnum.Current;

//Skip predicate if it is not an element
if (predNode.NodeType != XmlNodeType.Element)
continue;

//Get the predicate
RDFResource pred;
XmlAttribute xmlLangPred = GetXmlLangAttribute(predNode) ?? xmlLangSubj;
if (predNode.NamespaceURI == string.Empty)
pred = new RDFResource(string.Concat(xmlBase, predNode.LocalName), hashContext);
Expand Down Expand Up @@ -1071,11 +1063,8 @@ private static void ParseContainerElements(RDFModelEnums.RDFContainerTypes contT
if (container.HasChildNodes)
{
List<string> elemVals = new List<string>();
IEnumerator elems = container.ChildNodes.GetEnumerator();
while (elems != null && elems.MoveNext())
foreach (XmlNode elem in container.ChildNodes)
{
XmlNode elem = (XmlNode)elems.Current;

//Skip container item if it is not an element
if (elem.NodeType != XmlNodeType.Element)
continue;
Expand Down
6 changes: 2 additions & 4 deletions RDFSharp/Query/Mirella/Algebra/Queries/RDFAskQueryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

using System;
using System.Collections;
using System.ComponentModel;
using System.IO;
using System.Threading.Tasks;
using System.Xml;
Expand Down Expand Up @@ -138,11 +139,8 @@ public static RDFAskQueryResult FromSparqlXmlResult(Stream inputStream)
#region parse
bool foundHead = false;
bool foundBoolean = false;
IEnumerator nodesEnum = srxDoc.DocumentElement.ChildNodes.GetEnumerator();
while (nodesEnum?.MoveNext() ?? false)
foreach (XmlNode node in srxDoc.DocumentElement.ChildNodes)
{
XmlNode node = (XmlNode)nodesEnum.Current;

#region HEAD
if (string.Equals(node.Name, "HEAD", StringComparison.OrdinalIgnoreCase))
foundHead = true;
Expand Down
18 changes: 4 additions & 14 deletions RDFSharp/Query/Mirella/Algebra/Queries/RDFSelectQueryResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,23 +235,18 @@ public static RDFSelectQueryResult FromSparqlXmlResult(Stream inputStream)
#region results
bool foundHead = false;
bool foundResults = false;
IEnumerator nodesEnum = srxDoc.DocumentElement.ChildNodes.GetEnumerator();
while (nodesEnum?.MoveNext() ?? false)
foreach (XmlNode node in srxDoc.DocumentElement.ChildNodes)
{
XmlNode node = (XmlNode)nodesEnum.Current;

#region HEAD
if (string.Equals(node.Name, "HEAD", StringComparison.OrdinalIgnoreCase))
{
if (!node.HasChildNodes)
throw new Exception("\"head\" node was found without children.");

foundHead = true;
IEnumerator variablesEnum = node.ChildNodes.GetEnumerator();
while (variablesEnum?.MoveNext() ?? false)
foreach (XmlNode varNode in node.ChildNodes)
{
#region VARIABLE
XmlNode varNode = (XmlNode)variablesEnum.Current;
if (string.Equals(varNode.Name, "VARIABLE", StringComparison.OrdinalIgnoreCase))
{
if (varNode.Attributes == null || varNode.Attributes.Count == 0)
Expand All @@ -273,21 +268,16 @@ public static RDFSelectQueryResult FromSparqlXmlResult(Stream inputStream)
throw new Exception("\"head\" node was not found, or was after \"results\" node.");

foundResults = true;
IEnumerator resultsEnum = node.ChildNodes.GetEnumerator();
while (resultsEnum?.MoveNext() ?? false)
foreach (XmlNode resNode in node.ChildNodes)
{
XmlNode resNode = (XmlNode)resultsEnum.Current;

#region RESULT
if (string.Equals(resNode.Name, "RESULT", StringComparison.OrdinalIgnoreCase))
{
if (resNode.HasChildNodes)
{
Dictionary<string, string> results = new Dictionary<string, string>();
IEnumerator bindingsEnum = resNode.ChildNodes.GetEnumerator();
while (bindingsEnum?.MoveNext() ?? false)
foreach (XmlNode bindingNode in resNode.ChildNodes)
{
XmlNode bindingNode = (XmlNode)bindingsEnum.Current;
bool foundUri = false;
bool foundLit = false;

Expand Down
9 changes: 2 additions & 7 deletions RDFSharp/Store/Serializers/RDFTriX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,8 @@ internal static RDFMemoryStore Deserialize(Stream inputStream)
#endregion Guards

Dictionary<string, long> hashContext = new Dictionary<string, long>();
IEnumerator graphEnum = trixDoc.DocumentElement.ChildNodes.GetEnumerator();
while (graphEnum != null && graphEnum.MoveNext())
foreach (XmlNode graph in trixDoc.DocumentElement.ChildNodes)
{
XmlNode graph = (XmlNode)graphEnum.Current;
if (!graph.Name.Equals("graph", StringComparison.Ordinal))
throw new Exception(" a \"<graph>\" element was expected, instead of unrecognized \"<" + graph.Name + ">\".");

Expand All @@ -137,11 +135,8 @@ internal static RDFMemoryStore Deserialize(Stream inputStream)
graphs.Add(graphID, new RDFGraph().SetContext(graphUri));

long encodedUris = 0;
IEnumerator graphChildren = graph.ChildNodes.GetEnumerator();
while (graphChildren != null && graphChildren.MoveNext())
foreach (XmlNode graphChild in graph.ChildNodes)
{
XmlNode graphChild = (XmlNode)graphChildren.Current;

#region <uri>

//<uri> gives the context of the graph
Expand Down

0 comments on commit 7c7fa32

Please sign in to comment.