Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/XPath2/XPath2Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,18 @@
{
if (value == null)
return Undefined.Value;
XmlNode xmlNode = value as XmlNode;
if (xmlNode != null)

if (value is XmlNode xmlNode)
return xmlNode.CreateNavigator();
XNode xnode = value as XNode;
if (xnode != null)
else if (value is XNode xnode)
return xnode.CreateNavigator();
XPath2NodeIterator iter = value as XPath2NodeIterator;
if (iter != null)
else if (value is XPath2NodeIterator)
return iter;
IEnumerable<XNode> en = value as IEnumerable<XNode>;
if (en != null)
else if (value is IEnumerable<XNode> en)
return new NodeIterator(CreateIterator(en));
IEnumerable<Object> eno = value as IEnumerable<Object>;
if (eno != null)
else if (value is IEnumerable<object> eno)
return new NodeIterator(CreateIterator(eno));

return value;
}

Expand Down Expand Up @@ -112,9 +109,11 @@
{
XPathNavigator curr = (XPathNavigator)item;
XObject o = (XObject)curr.UnderlyingObject;
if (!(o is T))

if (o is T t)
yield return t;
else
throw new InvalidOperationException(String.Format("Unexpected evaluation {0}", o.GetType()));
yield return (T)o;
}
else
throw new InvalidOperationException(String.Format("Unexpected evaluation {0}", item.TypedValue.GetType()));
Expand Down Expand Up @@ -191,16 +190,17 @@
public object Evaluate(IContextProvider provider, IDictionary<XmlQualifiedName, object> vars)
{
object res = ExpressionTree.Execute(provider, BindExpr(vars));
if (res is XPathItem)
if (res is XPathItem item)
{
XPathItem item = (XPathItem)res;
if (!item.IsNode)

Check warning on line 195 in src/XPath2/XPath2Expression.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Merge this if statement with the enclosing one.

See more on https://sonarcloud.io/project/issues?id=StefH_XPath2.Net&issues=AZ_RSGd5klQvbTTPgehN&open=AZ_RSGd5klQvbTTPgehN&pullRequest=74

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See Sonar info warning

res = item.TypedValue;
}

resultType = CoreFuncs.GetXPath2ResultType(res);
ValueProxy proxy = res as ValueProxy;
if (proxy != null)

if (res is ValueProxy proxy)
return proxy.Value;

return res;
}

Expand All @@ -211,7 +211,8 @@
{
Type type = props.GetType();
if (type.IsArray)
throw new ArgumentException("props");
throw new ArgumentException(nameof(props));

PropertyInfo[] propsInfo = type.GetProperties();
vars = new Dictionary<XmlQualifiedName, object>(propsInfo.Length);
for (int k = 0; k < propsInfo.Length; k++)
Expand All @@ -232,4 +233,5 @@
return resultType.Value;
}
}
}

}
Loading