-
Notifications
You must be signed in to change notification settings - Fork 2
/
UncheckedSignExtendingConverter.cs
37 lines (35 loc) · 1.36 KB
/
UncheckedSignExtendingConverter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Runtime.CompilerServices;
using Platform.Reflection;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
namespace Platform.Converters
{
/// <summary>
/// <para>
/// Represents the unchecked sign extending converter.
/// </para>
/// <para></para>
/// </summary>
/// <seealso cref="ConverterBase{TSource, TTarget}"/>
public abstract class UncheckedSignExtendingConverter<TSource, TTarget> : ConverterBase<TSource, TTarget>
{
/// <summary>
/// <para>
/// Gets the default value.
/// </para>
/// <para></para>
/// </summary>
public static UncheckedSignExtendingConverter<TSource, TTarget> Default
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get;
} = CompileUncheckedConverter();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static UncheckedSignExtendingConverter<TSource, TTarget> CompileUncheckedConverter()
{
var type = CreateTypeInheritedFrom<UncheckedSignExtendingConverter<TSource, TTarget>>();
EmitConvertMethod(type, il => il.UncheckedConvert<TSource, TTarget>(extendSign: true));
return (UncheckedSignExtendingConverter<TSource, TTarget>)Activator.CreateInstance(type.CreateTypeInfo());
}
}
}