Last active
February 21, 2016 15:34
-
-
Save benaadams/c6c109982f50c6f69af2 to your computer and use it in GitHub Desktop.
TypeOf Jit Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkDotNet; | |
using BenchmarkDotNet.Tasks; | |
using System; | |
using System.Runtime.CompilerServices; | |
namespace TypeOfBenchmark | |
{ | |
[BenchmarkTask(platform: BenchmarkPlatform.X64, jitVersion: BenchmarkJitVersion.RyuJit)] | |
public class GenericTypeOfTests | |
{ | |
static FeatureCollection fc = new FeatureCollection(); | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void NoBranchingCast() | |
{ | |
var t0 = fc.Get0Cast(); | |
var t1 = fc.Get1Cast(); | |
var t2 = fc.Get2Cast(); | |
var t3 = fc.Get3Cast(); | |
var t4 = fc.Get4Cast(); | |
var t5 = fc.Get5Cast(); | |
var t6 = fc.Get6Cast(); | |
var t7 = fc.Get7Cast(); | |
var t8 = fc.Get8Cast(); | |
var t9 = fc.Get9Cast(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void NoBranchingAsCast() | |
{ | |
var t0 = fc.Get0AsCast(); | |
var t1 = fc.Get1AsCast(); | |
var t2 = fc.Get2AsCast(); | |
var t3 = fc.Get3AsCast(); | |
var t4 = fc.Get4AsCast(); | |
var t5 = fc.Get5AsCast(); | |
var t6 = fc.Get6AsCast(); | |
var t7 = fc.Get7AsCast(); | |
var t8 = fc.Get8AsCast(); | |
var t9 = fc.Get9AsCast(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void GetGenericCast() | |
{ | |
var t0 = fc.GetGenericCast<IType0>(); | |
var t1 = fc.GetGenericCast<IType1>(); | |
var t2 = fc.GetGenericCast<IType2>(); | |
var t3 = fc.GetGenericCast<IType3>(); | |
var t4 = fc.GetGenericCast<IType4>(); | |
var t5 = fc.GetGenericCast<IType5>(); | |
var t6 = fc.GetGenericCast<IType6>(); | |
var t7 = fc.GetGenericCast<IType7>(); | |
var t8 = fc.GetGenericCast<IType8>(); | |
var t9 = fc.GetGenericCast<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void GetGenericAs() | |
{ | |
var t0 = fc.GetGenericAs<IType0>(); | |
var t1 = fc.GetGenericAs<IType1>(); | |
var t2 = fc.GetGenericAs<IType2>(); | |
var t3 = fc.GetGenericAs<IType3>(); | |
var t4 = fc.GetGenericAs<IType4>(); | |
var t5 = fc.GetGenericAs<IType5>(); | |
var t6 = fc.GetGenericAs<IType6>(); | |
var t7 = fc.GetGenericAs<IType7>(); | |
var t8 = fc.GetGenericAs<IType8>(); | |
var t9 = fc.GetGenericAs<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void GetTypeOfExtensionCast() | |
{ | |
var t0 = fc.GetTypeOfExtensionCast<IType0>(); | |
var t1 = fc.GetTypeOfExtensionCast<IType1>(); | |
var t2 = fc.GetTypeOfExtensionCast<IType2>(); | |
var t3 = fc.GetTypeOfExtensionCast<IType3>(); | |
var t4 = fc.GetTypeOfExtensionCast<IType4>(); | |
var t5 = fc.GetTypeOfExtensionCast<IType5>(); | |
var t6 = fc.GetTypeOfExtensionCast<IType6>(); | |
var t7 = fc.GetTypeOfExtensionCast<IType7>(); | |
var t8 = fc.GetTypeOfExtensionCast<IType8>(); | |
var t9 = fc.GetTypeOfExtensionCast<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void GetGenericExtensionCastInline() | |
{ | |
var t0 = fc.GetGenericExtensionCastInline<IType0>(); | |
var t1 = fc.GetGenericExtensionCastInline<IType1>(); | |
var t2 = fc.GetGenericExtensionCastInline<IType2>(); | |
var t3 = fc.GetGenericExtensionCastInline<IType3>(); | |
var t4 = fc.GetGenericExtensionCastInline<IType4>(); | |
var t5 = fc.GetGenericExtensionCastInline<IType5>(); | |
var t6 = fc.GetGenericExtensionCastInline<IType6>(); | |
var t7 = fc.GetGenericExtensionCastInline<IType7>(); | |
var t8 = fc.GetGenericExtensionCastInline<IType8>(); | |
var t9 = fc.GetGenericExtensionCastInline<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void GetTypeOfExtensionAs() | |
{ | |
var t0 = fc.GetTypeOfExtensionAs<IType0>(); | |
var t1 = fc.GetTypeOfExtensionAs<IType1>(); | |
var t2 = fc.GetTypeOfExtensionAs<IType2>(); | |
var t3 = fc.GetTypeOfExtensionAs<IType3>(); | |
var t4 = fc.GetTypeOfExtensionAs<IType4>(); | |
var t5 = fc.GetTypeOfExtensionAs<IType5>(); | |
var t6 = fc.GetTypeOfExtensionAs<IType6>(); | |
var t7 = fc.GetTypeOfExtensionAs<IType7>(); | |
var t8 = fc.GetTypeOfExtensionAs<IType8>(); | |
var t9 = fc.GetTypeOfExtensionAs<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void GetGenericExtensionCast() | |
{ | |
var t0 = fc.GetGenericExtensionCast<IType0>(); | |
var t1 = fc.GetGenericExtensionCast<IType1>(); | |
var t2 = fc.GetGenericExtensionCast<IType2>(); | |
var t3 = fc.GetGenericExtensionCast<IType3>(); | |
var t4 = fc.GetGenericExtensionCast<IType4>(); | |
var t5 = fc.GetGenericExtensionCast<IType5>(); | |
var t6 = fc.GetGenericExtensionCast<IType6>(); | |
var t7 = fc.GetGenericExtensionCast<IType7>(); | |
var t8 = fc.GetGenericExtensionCast<IType8>(); | |
var t9 = fc.GetGenericExtensionCast<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void GetGenericExtenstionAs() | |
{ | |
var t0 = fc.GetGenericExtenstionAs<IType0>(); | |
var t1 = fc.GetGenericExtenstionAs<IType1>(); | |
var t2 = fc.GetGenericExtenstionAs<IType2>(); | |
var t3 = fc.GetGenericExtenstionAs<IType3>(); | |
var t4 = fc.GetGenericExtenstionAs<IType4>(); | |
var t5 = fc.GetGenericExtenstionAs<IType5>(); | |
var t6 = fc.GetGenericExtenstionAs<IType6>(); | |
var t7 = fc.GetGenericExtenstionAs<IType7>(); | |
var t8 = fc.GetGenericExtenstionAs<IType8>(); | |
var t9 = fc.GetGenericExtenstionAs<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void GetGenericStructUnwrap() | |
{ | |
var t0 = fc.GetGenericStructUnwrap<IType0>(); | |
var t1 = fc.GetGenericStructUnwrap<IType1>(); | |
var t2 = fc.GetGenericStructUnwrap<IType2>(); | |
var t3 = fc.GetGenericStructUnwrap<IType3>(); | |
var t4 = fc.GetGenericStructUnwrap<IType4>(); | |
var t5 = fc.GetGenericStructUnwrap<IType5>(); | |
var t6 = fc.GetGenericStructUnwrap<IType6>(); | |
var t7 = fc.GetGenericStructUnwrap<IType7>(); | |
var t8 = fc.GetGenericStructUnwrap<IType8>(); | |
var t9 = fc.GetGenericStructUnwrap<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void GetGenericStructWrapped() | |
{ | |
var t0 = fc.GetGenericStructWrapped<IType0>(); | |
var t1 = fc.GetGenericStructWrapped<IType1>(); | |
var t2 = fc.GetGenericStructWrapped<IType2>(); | |
var t3 = fc.GetGenericStructWrapped<IType3>(); | |
var t4 = fc.GetGenericStructWrapped<IType4>(); | |
var t5 = fc.GetGenericStructWrapped<IType5>(); | |
var t6 = fc.GetGenericStructWrapped<IType6>(); | |
var t7 = fc.GetGenericStructWrapped<IType7>(); | |
var t8 = fc.GetGenericStructWrapped<IType8>(); | |
var t9 = fc.GetGenericStructWrapped<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void GetConcreteStructWrapped() | |
{ | |
var t0 = fc.GetConcreteStructWrapped<StructWrapperIType0>().Current; | |
var t1 = fc.GetConcreteStructWrapped<StructWrapperIType1>().Current; | |
var t2 = fc.GetConcreteStructWrapped<StructWrapperIType2>().Current; | |
var t3 = fc.GetConcreteStructWrapped<StructWrapperIType3>().Current; | |
var t4 = fc.GetConcreteStructWrapped<StructWrapperIType4>().Current; | |
var t5 = fc.GetConcreteStructWrapped<StructWrapperIType5>().Current; | |
var t6 = fc.GetConcreteStructWrapped<StructWrapperIType6>().Current; | |
var t7 = fc.GetConcreteStructWrapped<StructWrapperIType7>().Current; | |
var t8 = fc.GetConcreteStructWrapped<StructWrapperIType8>().Current; | |
var t9 = fc.GetConcreteStructWrapped<StructWrapperIType9>().Current; | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void INoBranchingCast() | |
{ | |
IFeatureCollection ifc = fc; | |
var t0 = ifc.Get0Cast(); | |
var t1 = ifc.Get1Cast(); | |
var t2 = ifc.Get2Cast(); | |
var t3 = ifc.Get3Cast(); | |
var t4 = ifc.Get4Cast(); | |
var t5 = ifc.Get5Cast(); | |
var t6 = ifc.Get6Cast(); | |
var t7 = ifc.Get7Cast(); | |
var t8 = ifc.Get8Cast(); | |
var t9 = ifc.Get9Cast(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void IGetGenericCast() | |
{ | |
IFeatureCollection ifc = fc; | |
var t0 = ifc.GetGenericCast<IType0>(); | |
var t1 = ifc.GetGenericCast<IType1>(); | |
var t2 = ifc.GetGenericCast<IType2>(); | |
var t3 = ifc.GetGenericCast<IType3>(); | |
var t4 = ifc.GetGenericCast<IType4>(); | |
var t5 = ifc.GetGenericCast<IType5>(); | |
var t6 = ifc.GetGenericCast<IType6>(); | |
var t7 = ifc.GetGenericCast<IType7>(); | |
var t8 = ifc.GetGenericCast<IType8>(); | |
var t9 = ifc.GetGenericCast<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void IGetTypeOfExtensionCast() | |
{ | |
IFeatureCollection ifc = fc; | |
var t0 = ifc.GetTypeOfExtensionCast<IType0>(); | |
var t1 = ifc.GetTypeOfExtensionCast<IType1>(); | |
var t2 = ifc.GetTypeOfExtensionCast<IType2>(); | |
var t3 = ifc.GetTypeOfExtensionCast<IType3>(); | |
var t4 = ifc.GetTypeOfExtensionCast<IType4>(); | |
var t5 = ifc.GetTypeOfExtensionCast<IType5>(); | |
var t6 = ifc.GetTypeOfExtensionCast<IType6>(); | |
var t7 = ifc.GetTypeOfExtensionCast<IType7>(); | |
var t8 = ifc.GetTypeOfExtensionCast<IType8>(); | |
var t9 = ifc.GetTypeOfExtensionCast<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void IGetGenericExtensionCastInline() | |
{ | |
IFeatureCollection ifc = fc; | |
var t0 = ifc.GetGenericExtensionCastInline<IType0>(); | |
var t1 = ifc.GetGenericExtensionCastInline<IType1>(); | |
var t2 = ifc.GetGenericExtensionCastInline<IType2>(); | |
var t3 = ifc.GetGenericExtensionCastInline<IType3>(); | |
var t4 = ifc.GetGenericExtensionCastInline<IType4>(); | |
var t5 = ifc.GetGenericExtensionCastInline<IType5>(); | |
var t6 = ifc.GetGenericExtensionCastInline<IType6>(); | |
var t7 = ifc.GetGenericExtensionCastInline<IType7>(); | |
var t8 = ifc.GetGenericExtensionCastInline<IType8>(); | |
var t9 = ifc.GetGenericExtensionCastInline<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void IGetGenericExtensionCast() | |
{ | |
IFeatureCollection ifc = fc; | |
var t0 = ifc.GetGenericExtensionCast<IType0>(); | |
var t1 = ifc.GetGenericExtensionCast<IType1>(); | |
var t2 = ifc.GetGenericExtensionCast<IType2>(); | |
var t3 = ifc.GetGenericExtensionCast<IType3>(); | |
var t4 = ifc.GetGenericExtensionCast<IType4>(); | |
var t5 = ifc.GetGenericExtensionCast<IType5>(); | |
var t6 = ifc.GetGenericExtensionCast<IType6>(); | |
var t7 = ifc.GetGenericExtensionCast<IType7>(); | |
var t8 = ifc.GetGenericExtensionCast<IType8>(); | |
var t9 = ifc.GetGenericExtensionCast<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void IGetGenericStructUnwrap() | |
{ | |
IFeatureCollection ifc = fc; | |
var t0 = ifc.GetGenericStructUnwrap<IType0>(); | |
var t1 = ifc.GetGenericStructUnwrap<IType1>(); | |
var t2 = ifc.GetGenericStructUnwrap<IType2>(); | |
var t3 = ifc.GetGenericStructUnwrap<IType3>(); | |
var t4 = ifc.GetGenericStructUnwrap<IType4>(); | |
var t5 = ifc.GetGenericStructUnwrap<IType5>(); | |
var t6 = ifc.GetGenericStructUnwrap<IType6>(); | |
var t7 = ifc.GetGenericStructUnwrap<IType7>(); | |
var t8 = ifc.GetGenericStructUnwrap<IType8>(); | |
var t9 = ifc.GetGenericStructUnwrap<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void IGetGenericStructWrapped() | |
{ | |
IFeatureCollection ifc = fc; | |
var t0 = ifc.GetGenericStructWrapped<IType0>(); | |
var t1 = ifc.GetGenericStructWrapped<IType1>(); | |
var t2 = ifc.GetGenericStructWrapped<IType2>(); | |
var t3 = ifc.GetGenericStructWrapped<IType3>(); | |
var t4 = ifc.GetGenericStructWrapped<IType4>(); | |
var t5 = ifc.GetGenericStructWrapped<IType5>(); | |
var t6 = ifc.GetGenericStructWrapped<IType6>(); | |
var t7 = ifc.GetGenericStructWrapped<IType7>(); | |
var t8 = ifc.GetGenericStructWrapped<IType8>(); | |
var t9 = ifc.GetGenericStructWrapped<IType9>(); | |
} | |
[Benchmark] | |
[OperationsPerInvoke(2)] | |
public void IGetConcreteStructWrapped() | |
{ | |
IFeatureCollection ifc = fc; | |
var t0 = ifc.GetConcreteStructWrapped<StructWrapperIType0>().Current; | |
var t1 = ifc.GetConcreteStructWrapped<StructWrapperIType1>().Current; | |
var t2 = ifc.GetConcreteStructWrapped<StructWrapperIType2>().Current; | |
var t3 = ifc.GetConcreteStructWrapped<StructWrapperIType3>().Current; | |
var t4 = ifc.GetConcreteStructWrapped<StructWrapperIType4>().Current; | |
var t5 = ifc.GetConcreteStructWrapped<StructWrapperIType5>().Current; | |
var t6 = ifc.GetConcreteStructWrapped<StructWrapperIType6>().Current; | |
var t7 = ifc.GetConcreteStructWrapped<StructWrapperIType7>().Current; | |
var t8 = ifc.GetConcreteStructWrapped<StructWrapperIType8>().Current; | |
var t9 = ifc.GetConcreteStructWrapped<StructWrapperIType9>().Current; | |
} | |
} | |
public interface IType0 { } | |
public interface IType1 { } | |
public interface IType2 { } | |
public interface IType3 { } | |
public interface IType4 { } | |
public interface IType5 { } | |
public interface IType6 { } | |
public interface IType7 { } | |
public interface IType8 { } | |
public interface IType9 { } | |
public struct StructWrapper<T> | |
{ | |
public T Current; | |
public StructWrapper(T o) | |
{ | |
Current = o; | |
} | |
} | |
public interface IStructWapper<T> | |
{ | |
T Current { get; } | |
} | |
public struct StructWrapperIType0 : IStructWapper<IType0> | |
{ | |
public IType0 Current { get; } | |
public StructWrapperIType0(IType0 o) | |
{ | |
Current = o; | |
} | |
} | |
public struct StructWrapperIType1 : IStructWapper<IType1> | |
{ | |
public IType1 Current { get; } | |
public StructWrapperIType1(IType1 o) | |
{ | |
Current = o; | |
} | |
} | |
public struct StructWrapperIType2 : IStructWapper<IType2> | |
{ | |
public IType2 Current { get; } | |
public StructWrapperIType2(IType2 o) | |
{ | |
Current = o; | |
} | |
} | |
public struct StructWrapperIType3 : IStructWapper<IType3> | |
{ | |
public IType3 Current { get; } | |
public StructWrapperIType3(IType3 o) | |
{ | |
Current = o; | |
} | |
} | |
public struct StructWrapperIType4 : IStructWapper<IType4> | |
{ | |
public IType4 Current { get; } | |
public StructWrapperIType4(IType4 o) | |
{ | |
Current = o; | |
} | |
} | |
public struct StructWrapperIType5 : IStructWapper<IType5> | |
{ | |
public IType5 Current { get; } | |
public StructWrapperIType5(IType5 o) | |
{ | |
Current = o; | |
} | |
} | |
public struct StructWrapperIType6 : IStructWapper<IType6> | |
{ | |
public IType6 Current { get; } | |
public StructWrapperIType6(IType6 o) | |
{ | |
Current = o; | |
} | |
} | |
public struct StructWrapperIType7 : IStructWapper<IType7> | |
{ | |
public IType7 Current { get; } | |
public StructWrapperIType7(IType7 o) | |
{ | |
Current = o; | |
} | |
} | |
public struct StructWrapperIType8 : IStructWapper<IType8> | |
{ | |
public IType8 Current { get; } | |
public StructWrapperIType8(IType8 o) | |
{ | |
Current = o; | |
} | |
} | |
public struct StructWrapperIType9 : IStructWapper<IType9> | |
{ | |
public IType9 Current { get; } | |
public StructWrapperIType9(IType9 o) | |
{ | |
Current = o; | |
} | |
} | |
public class ClassWrapper<T> | |
{ | |
public T obj; | |
public ClassWrapper(T o) | |
{ | |
obj = o; | |
} | |
} | |
public interface IFeatureCollection | |
{ | |
object Get(Type T); | |
object Get<T>(); | |
IType0 Get0AsCast(); | |
IType0 Get0Cast(); | |
IType1 Get1AsCast(); | |
IType1 Get1Cast(); | |
IType2 Get2AsCast(); | |
IType2 Get2Cast(); | |
IType3 Get3AsCast(); | |
IType3 Get3Cast(); | |
IType4 Get4AsCast(); | |
IType4 Get4Cast(); | |
IType5 Get5AsCast(); | |
IType5 Get5Cast(); | |
IType6 Get6AsCast(); | |
IType6 Get6Cast(); | |
IType7 Get7AsCast(); | |
IType7 Get7Cast(); | |
IType8 Get8AsCast(); | |
IType8 Get8Cast(); | |
IType9 Get9AsCast(); | |
IType9 Get9Cast(); | |
T GetGenericAs<T>() where T : class; | |
T GetGenericCast<T>(); | |
object GetInline<T>(); | |
TResult GetStructUnwrap<T, TResult>(); | |
T GetStructWrapped<T>(); | |
T GetConcreteStructWrapped<T>(); | |
} | |
public class FeatureCollection : IType0, IType1, IType2, IType3, IType4, IType5, IType6, IType7, IType8, IType9, IFeatureCollection | |
{ | |
private StructWrapper<IType0> _wrapped0; | |
private StructWrapper<IType1> _wrapped1; | |
private StructWrapper<IType2> _wrapped2; | |
private StructWrapper<IType3> _wrapped3; | |
private StructWrapper<IType4> _wrapped4; | |
private StructWrapper<IType5> _wrapped5; | |
private StructWrapper<IType6> _wrapped6; | |
private StructWrapper<IType7> _wrapped7; | |
private StructWrapper<IType8> _wrapped8; | |
private StructWrapper<IType9> _wrapped9; | |
private StructWrapperIType0 _wrappedI0; | |
private StructWrapperIType1 _wrappedI1; | |
private StructWrapperIType2 _wrappedI2; | |
private StructWrapperIType3 _wrappedI3; | |
private StructWrapperIType4 _wrappedI4; | |
private StructWrapperIType5 _wrappedI5; | |
private StructWrapperIType6 _wrappedI6; | |
private StructWrapperIType7 _wrappedI7; | |
private StructWrapperIType8 _wrappedI8; | |
private StructWrapperIType9 _wrappedI9; | |
public FeatureCollection() | |
{ | |
_wrapped0 = new StructWrapper<IType0>(this); | |
_wrapped1 = new StructWrapper<IType1>(this); | |
_wrapped2 = new StructWrapper<IType2>(this); | |
_wrapped3 = new StructWrapper<IType3>(this); | |
_wrapped4 = new StructWrapper<IType4>(this); | |
_wrapped5 = new StructWrapper<IType5>(this); | |
_wrapped6 = new StructWrapper<IType6>(this); | |
_wrapped7 = new StructWrapper<IType7>(this); | |
_wrapped8 = new StructWrapper<IType8>(this); | |
_wrapped9 = new StructWrapper<IType9>(this); | |
_wrappedI0 = new StructWrapperIType0(this); | |
_wrappedI1 = new StructWrapperIType1(this); | |
_wrappedI2 = new StructWrapperIType2(this); | |
_wrappedI3 = new StructWrapperIType3(this); | |
_wrappedI4 = new StructWrapperIType4(this); | |
_wrappedI5 = new StructWrapperIType5(this); | |
_wrappedI6 = new StructWrapperIType6(this); | |
_wrappedI7 = new StructWrapperIType7(this); | |
_wrappedI8 = new StructWrapperIType8(this); | |
_wrappedI9 = new StructWrapperIType9(this); | |
} | |
public IType0 Get0Cast() { return (IType0)(object)this; } | |
public IType1 Get1Cast() { return (IType1)(object)this; } | |
public IType2 Get2Cast() { return (IType2)(object)this; } | |
public IType3 Get3Cast() { return (IType3)(object)this; } | |
public IType4 Get4Cast() { return (IType4)(object)this; } | |
public IType5 Get5Cast() { return (IType5)(object)this; } | |
public IType6 Get6Cast() { return (IType6)(object)this; } | |
public IType7 Get7Cast() { return (IType7)(object)this; } | |
public IType8 Get8Cast() { return (IType8)(object)this; } | |
public IType9 Get9Cast() { return (IType9)(object)this; } | |
public IType0 Get0AsCast() { return (((object)this) as IType0); } | |
public IType1 Get1AsCast() { return (((object)this) as IType1); } | |
public IType2 Get2AsCast() { return (((object)this) as IType2); } | |
public IType3 Get3AsCast() { return (((object)this) as IType3); } | |
public IType4 Get4AsCast() { return (((object)this) as IType4); } | |
public IType5 Get5AsCast() { return (((object)this) as IType5); } | |
public IType6 Get6AsCast() { return (((object)this) as IType6); } | |
public IType7 Get7AsCast() { return (((object)this) as IType7); } | |
public IType8 Get8AsCast() { return (((object)this) as IType8); } | |
public IType9 Get9AsCast() { return (((object)this) as IType9); } | |
public object Get(Type T) | |
{ | |
if (T == typeof(IType0)) | |
{ | |
return this; | |
} | |
else if (T == typeof(IType1)) | |
{ | |
return this; | |
} | |
else if (T == typeof(IType2)) | |
{ | |
return this; | |
} | |
else if (T == typeof(IType3)) | |
{ | |
return this; | |
} | |
else if (T == typeof(IType4)) | |
{ | |
return this; | |
} | |
else if (T == typeof(IType5)) | |
{ | |
return this; | |
} | |
else if (T == typeof(IType6)) | |
{ | |
return this; | |
} | |
else if (T == typeof(IType7)) | |
{ | |
return this; | |
} | |
else if (T == typeof(IType8)) | |
{ | |
return this; | |
} | |
else if (T == typeof(IType9)) | |
{ | |
return this; | |
} | |
return null; | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public object GetInline<T>() | |
{ | |
if (typeof(T) == typeof(IType0)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType1)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType2)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType3)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType4)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType5)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType6)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType7)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType8)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType9)) | |
{ | |
return this; | |
} | |
return null; | |
} | |
public object Get<T>() | |
{ | |
if (typeof(T) == typeof(IType0)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType1)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType2)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType3)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType4)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType5)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType6)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType7)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType8)) | |
{ | |
return this; | |
} | |
else if (typeof(T) == typeof(IType9)) | |
{ | |
return this; | |
} | |
return null; | |
} | |
public T GetGenericCast<T>() | |
{ | |
if (typeof(T) == typeof(IType0)) | |
{ | |
return (T)(object)this; | |
} | |
else if (typeof(T) == typeof(IType1)) | |
{ | |
return (T)(object)this; | |
} | |
else if (typeof(T) == typeof(IType2)) | |
{ | |
return (T)(object)this; | |
} | |
else if (typeof(T) == typeof(IType3)) | |
{ | |
return (T)(object)this; | |
} | |
else if (typeof(T) == typeof(IType4)) | |
{ | |
return (T)(object)this; | |
} | |
else if (typeof(T) == typeof(IType5)) | |
{ | |
return (T)(object)this; | |
} | |
else if (typeof(T) == typeof(IType6)) | |
{ | |
return (T)(object)this; | |
} | |
else if (typeof(T) == typeof(IType7)) | |
{ | |
return (T)(object)this; | |
} | |
else if (typeof(T) == typeof(IType8)) | |
{ | |
return (T)(object)this; | |
} | |
else if (typeof(T) == typeof(IType9)) | |
{ | |
return (T)(object)this; | |
} | |
return default(T); | |
} | |
public TResult GetStructUnwrap<T, TResult>() | |
{ | |
if (typeof(T) == typeof(StructWrapper<IType0>)) | |
{ | |
return (TResult)_wrapped0.Current; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType1>)) | |
{ | |
return (TResult)_wrapped1.Current; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType2>)) | |
{ | |
return (TResult)_wrapped2.Current; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType3>)) | |
{ | |
return (TResult)_wrapped3.Current; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType4>)) | |
{ | |
return (TResult)_wrapped4.Current; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType5>)) | |
{ | |
return (TResult)_wrapped5.Current; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType6>)) | |
{ | |
return (TResult)_wrapped6.Current; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType7>)) | |
{ | |
return (TResult)_wrapped7.Current; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType8>)) | |
{ | |
return (TResult)_wrapped8.Current; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType9>)) | |
{ | |
return (TResult)_wrapped9.Current; | |
} | |
return default(TResult); | |
} | |
public T GetStructWrapped<T>() | |
{ | |
if (typeof(T) == typeof(StructWrapper<IType0>)) | |
{ | |
return (T)(object)_wrapped0; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType1>)) | |
{ | |
return (T)(object)_wrapped1; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType2>)) | |
{ | |
return (T)(object)_wrapped2; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType3>)) | |
{ | |
return (T)(object)_wrapped3; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType4>)) | |
{ | |
return (T)(object)_wrapped4; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType5>)) | |
{ | |
return (T)(object)_wrapped5; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType6>)) | |
{ | |
return (T)(object)_wrapped6; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType7>)) | |
{ | |
return (T)(object)_wrapped7; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType8>)) | |
{ | |
return (T)(object)_wrapped8; | |
} | |
else if (typeof(T) == typeof(StructWrapper<IType9>)) | |
{ | |
return (T)(object)_wrapped9; | |
} | |
return default(T); | |
} | |
public T GetConcreteStructWrapped<T>() | |
{ | |
if (typeof(T) == typeof(StructWrapperIType0)) | |
{ | |
return (T)(object)_wrappedI0; | |
} | |
else if (typeof(T) == typeof(StructWrapperIType1)) | |
{ | |
return (T)(object)_wrappedI1; | |
} | |
else if (typeof(T) == typeof(StructWrapperIType2)) | |
{ | |
return (T)(object)_wrappedI2; | |
} | |
else if (typeof(T) == typeof(StructWrapperIType3)) | |
{ | |
return (T)(object)_wrappedI3; | |
} | |
else if (typeof(T) == typeof(StructWrapperIType4)) | |
{ | |
return (T)(object)_wrappedI4; | |
} | |
else if (typeof(T) == typeof(StructWrapperIType5)) | |
{ | |
return (T)(object)_wrappedI5; | |
} | |
else if (typeof(T) == typeof(StructWrapperIType6)) | |
{ | |
return (T)(object)_wrappedI6; | |
} | |
else if (typeof(T) == typeof(StructWrapperIType7)) | |
{ | |
return (T)(object)_wrappedI7; | |
} | |
else if (typeof(T) == typeof(StructWrapperIType8)) | |
{ | |
return (T)(object)_wrappedI8; | |
} | |
else if (typeof(T) == typeof(StructWrapperIType9)) | |
{ | |
return (T)(object)_wrappedI9; | |
} | |
return default(T); | |
} | |
public T GetGenericAs<T>() where T : class | |
{ | |
if (typeof(T) == typeof(IType0)) | |
{ | |
return this as T; | |
} | |
else if (typeof(T) == typeof(IType1)) | |
{ | |
return this as T; | |
} | |
else if (typeof(T) == typeof(IType2)) | |
{ | |
return this as T; | |
} | |
else if (typeof(T) == typeof(IType3)) | |
{ | |
return this as T; | |
} | |
else if (typeof(T) == typeof(IType4)) | |
{ | |
return this as T; | |
} | |
else if (typeof(T) == typeof(IType5)) | |
{ | |
return this as T; | |
} | |
else if (typeof(T) == typeof(IType6)) | |
{ | |
return this as T; | |
} | |
else if (typeof(T) == typeof(IType7)) | |
{ | |
return this as T; | |
} | |
else if (typeof(T) == typeof(IType8)) | |
{ | |
return this as T; | |
} | |
else if (typeof(T) == typeof(IType9)) | |
{ | |
return this as T; | |
} | |
return null; | |
} | |
} | |
public static class FeatureCollectionExtensions | |
{ | |
public static T GetTypeOfExtensionCast<T>(this FeatureCollection features) | |
{ | |
return (T)features.Get(typeof(T)); | |
} | |
public static T GetTypeOfExtensionAs<T>(this FeatureCollection features) where T : class | |
{ | |
return features.Get(typeof(T)) as T; | |
} | |
public static T GetGenericExtensionCast<T>(this FeatureCollection features) | |
{ | |
return (T)features.Get<T>(); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static T GetGenericExtensionCastInline<T>(this FeatureCollection features) | |
{ | |
return (T)features.GetInline<T>(); | |
} | |
public static T GetGenericExtenstionAs<T>(this FeatureCollection features) where T : class | |
{ | |
return features.Get<T>() as T; | |
} | |
public static T GetGenericStructUnwrap<T>(this FeatureCollection features) | |
{ | |
return features.GetStructUnwrap<StructWrapper<T>, T>(); | |
} | |
public static T GetGenericStructWrapped<T>(this FeatureCollection features) | |
{ | |
return features.GetStructWrapped<StructWrapper<T>>().Current; | |
} | |
} | |
public static class IFeatureCollectionExtensions | |
{ | |
public static T GetTypeOfExtensionCast<T>(this IFeatureCollection features) | |
{ | |
return (T)features.Get(typeof(T)); | |
} | |
public static T GetGenericExtensionCast<T>(this IFeatureCollection features) | |
{ | |
return (T)features.Get<T>(); | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static T GetGenericExtensionCastInline<T>(this IFeatureCollection features) | |
{ | |
return (T)features.GetInline<T>(); | |
} | |
public static T GetGenericStructUnwrap<T>(this IFeatureCollection features) | |
{ | |
return features.GetStructUnwrap<StructWrapper<T>, T>(); | |
} | |
public static T GetGenericStructWrapped<T>(this IFeatureCollection features) | |
{ | |
return features.GetStructWrapped<StructWrapper<T>>().Current; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The changed interface implementation of FeatureCollection seems to cause the Jit to change inlining, and no longer inline the agressive inline method :-/
Fastest now being
IGetConcreteStructWrapped
which causes a concrete implementation of the generic function rather than a shared method