Ejemplo n.º 1
0
 private static void Compare(string value1, string value2, ComparisonCallback del)
 {
     if (!StringUtils.AreEqual(value1, value2, StringComparison.InvariantCultureIgnoreCase))
     {
         del(true);
     }
     else
     {
         del(false);
     }
 }
Ejemplo n.º 2
0
 private static void Compare(string value1, string value2, ComparisonCallback del)
 {
     if (!StringUtils.AreEqual(value1, value2, StringComparison.InvariantCultureIgnoreCase))
         del(true);
     else
         del(false);
 }
        static DecisionMappingPerfTest()
        {
            _lessThanDelegate         = LessThan;
            _lessThanInstanceDelegate = new DecisionMappingPerfTest().LessThanInstance;

            Expression <ComparisonCallback> expr = (a, b) => a.Value < b.Value;

            _lessThanExpression = expr.Compile();

            var delegateType       = typeof(ComparisonCallback);
            var argType            = typeof(Holder <int>);
            var resultType         = typeof(bool);
            var associatedWithType = typeof(DecisionMappingPerfTest);

            #region Dynamic method
            var dynMethod = new DynamicMethod("LessThan", resultType, new[] { argType, argType });
            EmitLessThan(dynMethod.GetILGenerator(), false);
            _lessThanDynamicMethod = (ComparisonCallback)dynMethod.CreateDelegate(delegateType);

            dynMethod = new DynamicMethod("LessThanAssoc", resultType, new[] { argType, argType }, associatedWithType);
            EmitLessThan(dynMethod.GetILGenerator(), false);
            _lessThanDynamicMethodAssociated = (ComparisonCallback)dynMethod.CreateDelegate(delegateType);

            dynMethod = new DynamicMethod(
                "LessThanAssocInstance", resultType,
                new[] { associatedWithType, argType, argType },
                associatedWithType);
            EmitLessThan(dynMethod.GetILGenerator(), true);
            _lessThanDynamicMethodAssociatedInstance =
                (ComparisonCallback)dynMethod.CreateDelegate(delegateType, new DecisionMappingPerfTest());
            #endregion

            #region Type builder
            var ab  = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("OpsHolder"), AssemblyBuilderAccess.RunAndCollect);
            var mod = ab.DefineDynamicModule("OpsHolder");
            var tb  = mod.DefineType("OpsHolder" + nameof(Int32));

            var mLessThan = tb.DefineMethod(
                "LessThan",
                MethodAttributes.Public | MethodAttributes.Static,
                resultType, new[] { argType, argType });
            EmitLessThan(mLessThan.GetILGenerator(), false);

            var mLessThanInstance = tb.DefineMethod(
                "LessThanInstance",
                MethodAttributes.Public,
                resultType, new[] { argType, argType });
            EmitLessThan(mLessThanInstance.GetILGenerator(), true);

            var mLessThanExpr = tb.DefineMethod(
                "LessThanExpr",
                MethodAttributes.Public | MethodAttributes.Static,
                resultType, new[] { argType, argType });
            expr.CompileToMethod(mLessThanExpr);

            var t2   = tb.CreateType();
            var inst = Activator.CreateInstance(t2);

            _lessThanTypeBuilder         = (ComparisonCallback)t2.GetMethod(mLessThan.Name).CreateDelegate(delegateType);
            _lessThanTypeBuilderInstance = (ComparisonCallback)t2.GetMethod(mLessThanInstance.Name).CreateDelegate(delegateType, inst);
            _lessThanTbExpression        =
                (ComparisonCallback)t2.GetMethod(mLessThanExpr.Name).CreateDelegate(delegateType);
            #endregion
        }