本文整理汇总了C#中El.GetValueOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# El.GetValueOrDefault方法的具体用法?C# El.GetValueOrDefault怎么用?C# El.GetValueOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类El
的用法示例。
在下文中一共展示了El.GetValueOrDefault方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifyNullableEnumLongToUShort
private static void VerifyNullableEnumLongToUShort(El? value, bool useInterpreter)
{
Expression<Func<ushort>> e =
Expression.Lambda<Func<ushort>>(
Expression.Convert(Expression.Constant(value, typeof(El?)), typeof(ushort)),
Enumerable.Empty<ParameterExpression>());
Func<ushort> f = e.Compile(useInterpreter);
if (value.HasValue)
Assert.Equal((ushort)value.GetValueOrDefault(), f());
else
Assert.Throws<InvalidOperationException>(() => f());
}
示例2: VerifyCheckedNullableEnumLongToSByte
private static void VerifyCheckedNullableEnumLongToSByte(El? value, bool useInterpreter)
{
Expression<Func<sbyte>> e =
Expression.Lambda<Func<sbyte>>(
Expression.ConvertChecked(Expression.Constant(value, typeof(El?)), typeof(sbyte)),
Enumerable.Empty<ParameterExpression>());
Func<sbyte> f = e.Compile(useInterpreter);
if (value.HasValue)
{
var unboxed = value.GetValueOrDefault();
if ((long)unboxed < sbyte.MinValue | (long)unboxed > sbyte.MaxValue)
Assert.Throws<OverflowException>(() => f());
else
Assert.Equal((sbyte)unboxed, f());
}
else
Assert.Throws<InvalidOperationException>(() => f());
}
示例3: VerifyCheckedNullableEnumLongToNullableULong
private static void VerifyCheckedNullableEnumLongToNullableULong(El? value, bool useInterpreter)
{
Expression<Func<ulong?>> e =
Expression.Lambda<Func<ulong?>>(
Expression.ConvertChecked(Expression.Constant(value, typeof(El?)), typeof(ulong?)),
Enumerable.Empty<ParameterExpression>());
Func<ulong?> f = e.Compile(useInterpreter);
if ((!value.HasValue))
Assert.Null(f());
else if (value.GetValueOrDefault() < 0)
Assert.Throws<OverflowException>(() => f());
else
Assert.Equal((ulong?)value.GetValueOrDefault(), f());
}
示例4: VerifyCheckedNullableEnumLongToEnum
private static void VerifyCheckedNullableEnumLongToEnum(El? value, bool useInterpreter)
{
Expression<Func<E>> e =
Expression.Lambda<Func<E>>(
Expression.ConvertChecked(Expression.Constant(value, typeof(El?)), typeof(E)),
Enumerable.Empty<ParameterExpression>());
Func<E> f = e.Compile(useInterpreter);
if (value.HasValue)
{
if ((long)value.GetValueOrDefault() < int.MinValue || (long)value.GetValueOrDefault() > int.MaxValue)
Assert.Throws<OverflowException>(() => f());
else
Assert.Equal((E)value.GetValueOrDefault(), f());
}
else
Assert.Throws<InvalidOperationException>(() => f());
}