本文整理汇总了C#中ILiteralNode.CompareTo方法的典型用法代码示例。如果您正苦于以下问题:C# ILiteralNode.CompareTo方法的具体用法?C# ILiteralNode.CompareTo怎么用?C# ILiteralNode.CompareTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILiteralNode
的用法示例。
在下文中一共展示了ILiteralNode.CompareTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AreLiteralsEqual
/// <summary>
/// Determines whether two Literals are equal
/// </summary>
/// <param name="a">First Literal</param>
/// <param name="b">Second Literal</param>
/// <returns></returns>
public static bool AreLiteralsEqual(ILiteralNode a, ILiteralNode b)
{
if (ReferenceEquals(a, b)) return true;
if (a == null)
{
if (b == null) return true;
return false;
}
else if (b == null)
{
return false;
}
//Language Tags must be equal (if present)
//If they don't have language tags then they'll both be set to String.Empty which will give true
if (a.Language.Equals(b.Language, StringComparison.OrdinalIgnoreCase))
{
//Datatypes must be equal (if present)
//If they don't have Data Types then they'll both be null
//Otherwise the URIs must be equal
if (a.DataType == null && b.DataType == null)
{
//Use String equality to get the result
return a.Value.Equals(b.Value, StringComparison.Ordinal);
}
else if (a.DataType == null)
{
//We have a Null DataType but the other Node doesn't so can't be equal
return false;
}
else if (b.DataType == null)
{
//The other Node has a Null DataType but we don't so can't be equal
return false;
}
else if (EqualityHelper.AreUrisEqual(a.DataType, b.DataType))
{
//We have equal DataTypes so use String Equality to evaluate
if (Options.LiteralEqualityMode == LiteralEqualityMode.Strict)
{
//Strict Equality Mode uses Ordinal Lexical Comparison for Equality as per W3C RDF Spec
return a.Value.Equals(b.Value, StringComparison.Ordinal);
}
else
{
//Loose Equality Mode uses Value Based Comparison for Equality of Typed Nodes
return (a.CompareTo(b) == 0);
}
}
else
{
//Data Types didn't match
return false;
}
}
else
{
//Language Tags didn't match
return false;
}
}