Exemple #1
0
        public JPadEvaluateExt Finalize(Sha1Provider sha1Provider, IDictionary <string, ComparerDelegate> comparers)
        {
            var cachedValues = this._valuesCache.Keys.OrderBy(k => _valuesCache[k]).ToArray();

            IDictionary <string, int>[] jumpTable = null;
            var paramTypes = new[]
            { typeof(JsonValue[]), typeof(IDictionary <string, int>[]), typeof(Sha1Provider), typeof(IDictionary <string, ComparerDelegate>) };
            var defaultConstructor =
                _closureType.DefineConstructor(MethodAttributes.Public | MethodAttributes.HideBySig,
                                               CallingConventions.Standard, paramTypes);
            var dcIL = defaultConstructor.GetILGenerator();

            dcIL.Emit(OpCodes.Ldarg_0);
            dcIL.Emit(OpCodes.Ldarg_1);
            dcIL.Emit(OpCodes.Ldarg_2);
            dcIL.Emit(OpCodes.Ldarg_3);
            dcIL.Emit(OpCodes.Ldarg_S, 4);
            dcIL.Emit(OpCodes.Call, typeof(EvaluatorDelegateClosure).GetConstructor(paramTypes) ?? throw new Exception("Cannot find constructor"));
            dcIL.Emit(OpCodes.Ret);

            var theType = _closureType.CreateType();

            var constructor = theType.GetConstructor(paramTypes);
            var closure     = (EvaluatorDelegateClosure)constructor.Invoke(new object[] { cachedValues, jumpTable, sha1Provider, comparers });

            Debug.Assert(closure != null, nameof(closure) + " != null");
            Save(theType, "test-analysis.dll");
            return(closure.Invoke);
        }
 public EvaluatorDelegateClosure(JsonValue[] cachedValues, IDictionary <string, int>[] jumpTable,
                                 Sha1Provider sha1Provider, IDictionary <string, ComparerDelegate> comparers)
 {
     this.cachedValues = cachedValues;
     this.jumpTable    = jumpTable;
     this.sha1Provider = sha1Provider;
     this.comparers    = comparers;
 }