public void Expressions_with_max_uint_constant() { const uint maxuint = UInt32.MaxValue; Assert.IsFalse(maxuint == -1); Assert.IsFalse(ExpressionCompiler.CompileFast(() => maxuint == -1)()); }
public void Expressions_with_larger_long_casts_should_not_crash() { var y = 65536; var yn1 = y + 1; Assert.IsTrue(ExpressionCompiler.CompileFast(() => yn1 != (long)y)()); }
public void Expressions_with_small_long_casts_should_not_crash() { var x = 65535; var y = 65535; Assert.IsTrue(ExpressionCompiler.CompileFast(() => x == (long)y)()); }
/// <summary> /// Compiles the static. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <returns></returns> public Func <IServiceProvider, TResult> CompileStatic <TResult>() { if (GetMethodInfo()?.IsStatic != true) { throw new NotSupportedException("Method must be a static method to compile as an static methods!"); } var(body, parameters) = base.Compile(); var lambda = Expression.Lambda <Func <IServiceProvider, TResult> >(body, parameters); return(ExpressionCompiler.CompileFast(lambda)); }
/// <summary> /// Compiles this instance. /// </summary> /// <returns></returns> public Action <object, IServiceProvider> Compile() { if (GetMethodInfo()?.IsStatic == true) { throw new NotSupportedException("Method must not be a static method to compile as an instance methods!"); } var(body, parameters) = base.Compile(); var lambda = Expression.Lambda <Action <object, IServiceProvider> >(body, parameters); return(ExpressionCompiler.CompileFast(lambda)); }
/// <summary> /// Compiles the static. /// </summary> /// <returns></returns> public Action <IServiceProvider, T> CompileStatic() { if (GetMethodInfo()?.IsStatic != true) { throw new NotSupportedException("Method must be a static method to compile as an static methods!"); } var(body, parameters) = base.Compile( typeof(T).GetTypeInfo()); var lambda = Expression.Lambda <Action <IServiceProvider, T> >(body, parameters); return(ExpressionCompiler.CompileFast(lambda)); }
/// <summary> /// Compiles this instance. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <returns></returns> public Func <object, IServiceProvider, T, TResult> Compile <TResult>() { if (GetMethodInfo()?.IsStatic == true) { throw new NotSupportedException("Method must not be a static method to compile as an instance methods!"); } var(body, parameters) = base.Compile( typeof(T).GetTypeInfo()); var lambda = Expression.Lambda <Func <object, IServiceProvider, T, TResult> >(body, parameters); return(ExpressionCompiler.CompileFast(lambda)); }
public void Can_return_constant() { Assert.AreEqual(ExpressionCompiler.CompileFast(() => 1u)(), 1u); Assert.AreEqual(ExpressionCompiler.CompileFast(() => (short)1)(), (short)1); Assert.AreEqual(ExpressionCompiler.CompileFast(() => 1L)(), 1L); Assert.AreEqual(ExpressionCompiler.CompileFast(() => 1uL)(), 1uL); Assert.AreEqual(ExpressionCompiler.CompileFast(() => (byte)1)(), (byte)1); Assert.AreEqual(ExpressionCompiler.CompileFast(() => (sbyte)1)(), (sbyte)1); Assert.AreEqual(ExpressionCompiler.CompileFast(() => 1)(), 1); Assert.AreEqual(ExpressionCompiler.CompileFast(() => 1.1f)(), 1.1f); Assert.AreEqual(ExpressionCompiler.CompileFast(() => 1.1d)(), 1.1d); Assert.AreEqual(ExpressionCompiler.CompileFast(() => 1.1M)(), 1.1M); Assert.AreEqual(ExpressionCompiler.CompileFast(() => 'c')(), 'c'); Assert.AreEqual(ExpressionCompiler.CompileFast(() => true)(), true); }
static Func <T, TProperty> CompileGetMethod(MethodInfo getMethod) { try { var instance = Expression.Parameter(typeof(T), "instance"); var call = Expression.Call(instance, getMethod); var lambdaExpression = Expression.Lambda <Func <T, TProperty> >(call, instance); return(ExpressionCompiler.CompileFast <Func <T, TProperty> >(lambdaExpression)); } catch (Exception ex) { throw new MassTransitException($"Failed to compile get method for property {getMethod.Name} on entity {typeof(T).Name}", ex); } }
/// <summary> /// Compiles this instance. /// </summary> /// <returns></returns> public Action <object, IServiceProvider, T, T2, T3, T4, T5> Compile() { if (GetMethodInfo()?.IsStatic == true) { throw new NotSupportedException("Method must not be a static method to compile as an instance methods!"); } var(body, parameters) = base.Compile( typeof(T).GetTypeInfo(), typeof(T2).GetTypeInfo(), typeof(T3).GetTypeInfo(), typeof(T4).GetTypeInfo(), typeof(T5).GetTypeInfo()); var lambda = Expression.Lambda <Action <object, IServiceProvider, T, T2, T3, T4, T5> >(body, parameters); return(ExpressionCompiler.CompileFast <Action <object, IServiceProvider, T, T2, T3, T4, T5> >(lambda)); }
/// <summary> /// Compiles the static. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <returns></returns> public Func <IServiceProvider, T, T2, T3, T4, T5, T6, TResult> CompileStatic <TResult>() { if (GetMethodInfo()?.IsStatic != true) { throw new NotSupportedException("Method must be a static method to compile as an static methods!"); } var(body, parameters) = base.Compile( typeof(T).GetTypeInfo(), typeof(T2).GetTypeInfo(), typeof(T3).GetTypeInfo(), typeof(T4).GetTypeInfo(), typeof(T5).GetTypeInfo(), typeof(T6).GetTypeInfo()); var lambda = Expression.Lambda <Func <IServiceProvider, T, T2, T3, T4, T5, T6, TResult> >(body, parameters); return(ExpressionCompiler.CompileFast <Func <IServiceProvider, T, T2, T3, T4, T5, T6, TResult> >(lambda)); }
static Action <T, TProperty> CompileSetMethod(Type implementationType, MethodInfo setMethod) { try { var instance = Expression.Parameter(typeof(T), "instance"); var value = Expression.Parameter(typeof(TProperty), "value"); var cast = Expression.TypeAs(instance, implementationType); var call = Expression.Call(cast, setMethod, value); var lambdaExpression = Expression.Lambda <Action <T, TProperty> >(call, instance, value); return(ExpressionCompiler.CompileFast <Action <T, TProperty> >(lambdaExpression)); } catch (Exception ex) { throw new MassTransitException($"Failed to compile SetMethod for property {setMethod.Name} on entity {typeof(T).Name}", ex); } }
/// <summary> /// Compiles the static. /// </summary> /// <returns></returns> public Action <IServiceProvider, T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> CompileStatic() { if (GetMethodInfo()?.IsStatic != true) { throw new NotSupportedException("Method must be a static method to compile as an static methods!"); } var(body, parameters) = base.Compile( typeof(T).GetTypeInfo(), typeof(T2).GetTypeInfo(), typeof(T3).GetTypeInfo(), typeof(T4).GetTypeInfo(), typeof(T5).GetTypeInfo(), typeof(T6).GetTypeInfo(), typeof(T7).GetTypeInfo(), typeof(T8).GetTypeInfo(), typeof(T9).GetTypeInfo(), typeof(T10).GetTypeInfo(), typeof(T11).GetTypeInfo()); var lambda = Expression.Lambda <Action <IServiceProvider, T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> >(body, parameters); return(ExpressionCompiler.CompileFast <Action <IServiceProvider, T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> >(lambda)); }
/// <summary> /// Compiles this instance. /// </summary> /// <typeparam name="TResult">The type of the result.</typeparam> /// <returns></returns> public Func <object, IServiceProvider, T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> Compile <TResult>() { if (GetMethodInfo()?.IsStatic == true) { throw new NotSupportedException("Method must not be a static method to compile as an instance methods!"); } var(body, parameters) = base.Compile( typeof(T).GetTypeInfo(), typeof(T2).GetTypeInfo(), typeof(T3).GetTypeInfo(), typeof(T4).GetTypeInfo(), typeof(T5).GetTypeInfo(), typeof(T6).GetTypeInfo(), typeof(T7).GetTypeInfo(), typeof(T8).GetTypeInfo(), typeof(T9).GetTypeInfo(), typeof(T10).GetTypeInfo(), typeof(T11).GetTypeInfo(), typeof(T12).GetTypeInfo()); var lambda = Expression.Lambda <Func <object, IServiceProvider, T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> >(body, parameters); return(ExpressionCompiler.CompileFast <Func <object, IServiceProvider, T, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, TResult> >(lambda)); }
public void Expressions_with_DateTime_and_double_constant() { Assert.IsFalse(ExpressionCompiler.CompileFast(() => (double)DateTime.Now.Day == 0d)()); }
public void Expressions_with_ulong_constants_and_casts() { Assert.IsFalse(ExpressionCompiler.CompileFast(() => 0UL == (ulong)"x".Length)()); }
public void Expressions_with_DateTime() { Assert.IsFalse(ExpressionCompiler.CompileFast(() => 0 == DateTime.Now.Day)()); }
public void Expressions_with_DateTime_and_ulong_constant() { Assert.IsFalse(ExpressionCompiler.CompileFast(() => 0UL == (ulong)DateTime.Now.Day)()); }
public void Expressions_with_DateTime_and_uint_constant() { Assert.IsFalse(ExpressionCompiler.CompileFast(() => 0u == (uint)DateTime.Now.Day, true)()); }
public void Expressions_with_char_and_short() { Assert.IsTrue(ExpressionCompiler.CompileFast(() => 'z' != (ushort)0)()); }
public void Expressions_with_DateTime_and_float_constant() { Assert.IsFalse(ExpressionCompiler.CompileFast(() => 0f == (float)DateTime.Now.Day)()); }
public void Expressions_with_char_and_int() { Assert.IsTrue(ExpressionCompiler.CompileFast(() => 'z' != 0, true)()); }