/// <summary> /// Tries to construct a new plan that calls a method on a /// receiver of the type given. May fail if there are no /// applicable methods or receivers available. /// </summary> /// <param name="type"></param> /// <param name="plan"></param> /// <returns></returns> private void NewMethodPlan(Type type, MethodInfo method, PlanManager planManager, bool forbidNull, Type[] methodArgumentTypes) { this.stats.Selected(MethodCall.Get(method).ToString()); PlanFilter f; if (forbidNull) { f = delegate(Plan p, int i) { if (!method.IsStatic && i == 0 && p.transformer is PrimitiveValueTransformer) { return(false); } // Non-null heuristic if (!methodArgumentTypes[i].IsValueType && (p.transformer is PrimitiveValueTransformer)) { return(false); } return(true); }; } else { f = delegate(Plan p, int i) { if (!method.IsStatic && i == 0 && p.transformer is PrimitiveValueTransformer) { return(false); } return(true); }; } RandomPlansResult r; if (!RandomPlans(out r, methodArgumentTypes, f, planManager.builderPlans, forbidNull, method)) { stats.CreatedNew(CreationResult.NoInputs); return; } //Console.WriteLine("\t\t A plan has been created"); Plan plan = new Plan(MethodCall.Get(method), r.fplans, r.fparameterChoosers); planManager.AddMaybeExecutingIfNeeded(plan, this.stats); }
/// <summary> /// Tries to construct a new plan that calls a method on a /// receiver of the type given. May fail if there are no /// applicable methods or receivers available. /// </summary> /// <param name="type"></param> /// <param name="plan"></param> /// <returns></returns> private void NewMethodPlan(Type type, MethodInfo method, PlanManager planManager, bool forbidNull, Type[] methodArgumentTypes) { stats.Selected(MethodCall.Get(method).ToString()); PlanFilter f; if (forbidNull) { f = delegate(Plan p, int i) { if (!method.IsStatic && i == 0 && p.transformer is PrimitiveValueTransformer) { return(false); } //// Non-null heuristic [email protected] //if (!methodArgumentTypes[i].IsValueType && (p.transformer is PrimitiveValueTransformer)) // return false; return(true); }; } else { f = delegate(Plan p, int i) { if (!method.IsStatic && i == 0 && p.transformer is PrimitiveValueTransformer) { return(false); } return(true); }; } if (!RandomPlans(out RandomPlansResult randomPlansResult, methodArgumentTypes, f, planManager.builderPlans, forbidNull, method)) { stats.CreatedNew(CreationResult.NoInputs); return; } //Logger.Debug("\t\t A plan has been created"); Plan plan = new Plan(MethodCall.Get(method), randomPlansResult.fplans, randomPlansResult.fparameterChoosers); plan.ClassName = method.DeclaringType.Name; planManager.AddMaybeExecutingIfNeeded(plan, stats); }