本文整理汇总了C#中SObject.TypeOf方法的典型用法代码示例。如果您正苦于以下问题:C# SObject.TypeOf方法的具体用法?C# SObject.TypeOf怎么用?C# SObject.TypeOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SObject
的用法示例。
在下文中一共展示了SObject.TypeOf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StrictEquals
/// <summary>
/// Compares two objects for equality, respecting their typings.
/// </summary>
/// <remarks>Used by the === and !== equality operators.</remarks>
public static bool StrictEquals(ScriptProcessor processor, SObject left, SObject right)
{
left = SObject.Unbox(left);
right = SObject.Unbox(right);
if (left.TypeOf() != right.TypeOf())
{
return false;
}
// If they are undefined or null, return true:
else if (left.TypeOf() == SObject.LITERAL_UNDEFINED || left.TypeOf() == SObject.LITERAL_NULL)
{
return true;
}
// Both are numbers:
else if (left.TypeOf() == SObject.LITERAL_TYPE_NUMBER)
{
var numLeft = ((SNumber)left).Value;
var numRight = ((SNumber)right).Value;
return numLeft == numRight;
}
// Both are string:
else if (left.TypeOf() == SObject.LITERAL_TYPE_STRING)
{
var strLeft = ((SString)left).Value;
var strRight = ((SString)right).Value;
return strLeft == strRight;
}
// Both are bool:
else if (left.TypeOf() == SObject.LITERAL_TYPE_BOOL)
{
var boolLeft = ((SBool)left).Value;
var boolRight = ((SBool)right).Value;
return boolLeft == boolRight;
}
else
{
return ReferenceEquals(left, right);
}
}
示例2: LooseEquals
/// <summary>
/// Compares two objects for equality, converting types if needed.
/// </summary>
/// <remarks>Used by the == and != equality operators.</remarks>
public static bool LooseEquals(ScriptProcessor processor, SObject left, SObject right)
{
left = SObject.Unbox(left);
right = SObject.Unbox(right);
// both types are the same:
if (left.TypeOf() == right.TypeOf())
{
// If they are undefined or null, return true:
if (left.TypeOf() == SObject.LITERAL_UNDEFINED || left.TypeOf() == SObject.LITERAL_NULL)
{
return true;
}
// Both are numbers:
else if (left.TypeOf() == SObject.LITERAL_TYPE_NUMBER)
{
var numLeft = ((SNumber)left).Value;
var numRight = ((SNumber)right).Value;
return numLeft == numRight;
}
// Both are string:
else if (left.TypeOf() == SObject.LITERAL_TYPE_STRING)
{
var strLeft = ((SString)left).Value;
var strRight = ((SString)right).Value;
return strLeft == strRight;
}
// Both are bool:
else if (left.TypeOf() == SObject.LITERAL_TYPE_BOOL)
{
var boolLeft = ((SBool)left).Value;
var boolRight = ((SBool)right).Value;
return boolLeft == boolRight;
}
else
{
return ReferenceEquals(left, right);
}
}
// null & undefined
else if (left.TypeOf() == SObject.LITERAL_NULL && right.TypeOf() == SObject.LITERAL_UNDEFINED ||
left.TypeOf() == SObject.LITERAL_UNDEFINED && right.TypeOf() == SObject.LITERAL_NULL)
{
return true;
}
// When one is a number and another is a string, convert the string to a number and compare:
else if (left.TypeOf() == SObject.LITERAL_TYPE_STRING && right.TypeOf() == SObject.LITERAL_TYPE_NUMBER)
{
var numLeft = left.ToNumber(processor).Value;
var numRight = ((SNumber)right).Value;
return numLeft == numRight;
}
else if (left.TypeOf() == SObject.LITERAL_TYPE_NUMBER && right.TypeOf() == SObject.LITERAL_TYPE_STRING)
{
var numRight = right.ToNumber(processor).Value;
var numLeft = ((SNumber)left).Value;
return numLeft == numRight;
}
else if (left.TypeOf() == SObject.LITERAL_TYPE_BOOL)
{
return LooseEquals(processor, left.ToNumber(processor), right);
}
else if (right.TypeOf() == SObject.LITERAL_TYPE_BOOL)
{
return LooseEquals(processor, left, right.ToNumber(processor));
}
else
{
return false;
}
}