本文整理汇总了C#中IEdmTypeReference.IsInt16方法的典型用法代码示例。如果您正苦于以下问题:C# IEdmTypeReference.IsInt16方法的具体用法?C# IEdmTypeReference.IsInt16怎么用?C# IEdmTypeReference.IsInt16使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEdmTypeReference
的用法示例。
在下文中一共展示了IEdmTypeReference.IsInt16方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryRewriteIntegralConstantNode
/// <summary>
/// Try to rewrite an Edm.Int32 constant node if its value is within the valid range of the target integer type.
/// </summary>
/// <param name="boundNode">The node to be rewritten.</param>
/// <param name="targetType">The target type reference.</param>
/// <returns>If the node is successfully rewritten.</returns>
private static bool TryRewriteIntegralConstantNode(ref SingleValueNode boundNode, IEdmTypeReference targetType)
{
if (targetType == null || !targetType.IsByte() && !targetType.IsSByte() && !targetType.IsInt16())
{
return false;
}
var constantNode = boundNode as ConstantNode;
if (constantNode == null)
{
return false;
}
var sourceType = constantNode.TypeReference;
if (sourceType == null || !sourceType.IsInt32())
{
return false;
}
var sourceValue = (int)constantNode.Value;
object targetValue = null;
switch (targetType.PrimitiveKind())
{
case EdmPrimitiveTypeKind.Byte:
if (sourceValue >= byte.MinValue && sourceValue <= byte.MaxValue)
{
targetValue = (byte)sourceValue;
}
break;
case EdmPrimitiveTypeKind.SByte:
if (sourceValue >= sbyte.MinValue && sourceValue <= sbyte.MaxValue)
{
targetValue = (sbyte)sourceValue;
}
break;
case EdmPrimitiveTypeKind.Int16:
if (sourceValue >= short.MinValue && sourceValue <= short.MaxValue)
{
targetValue = (short)sourceValue;
}
break;
}
if (targetValue == null)
{
return false;
}
boundNode = new ConstantNode(targetValue, constantNode.LiteralText, targetType);
return true;
}