예제 #1
0
 public static ConstructorCallTransformer Get(ConstructorInfo field)
 {
     ConstructorCallTransformer t;
     cachedTransformers.TryGetValue(field, out t);
     if (t == null)
         cachedTransformers[field] = t = new ConstructorCallTransformer(field);
     return t;
 }
예제 #2
0
        public override bool Equals(object obj)
        {
            ConstructorCallTransformer c = obj as ConstructorCallTransformer;

            if (c == null)
            {
                return(false);
            }
            return(this.fconstructor.Equals(c.fconstructor));
        }
예제 #3
0
        public static ConstructorCallTransformer Get(ConstructorInfo field)
        {
            ConstructorCallTransformer t;

            cachedTransformers.TryGetValue(field, out t);
            if (t == null)
            {
                cachedTransformers[field] = t = new ConstructorCallTransformer(field);
            }
            return(t);
        }
예제 #4
0
        /// <summary>
        /// Tries to construct a new plan that calls a constructor
        /// of the type given. May fail if there are no
        /// applicable constructors.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="plan"></param>
        /// <returns></returns>
        private void NewConstructorPlan(Type type, ConstructorInfo constructor, PlanManager planManager,
                                        bool forbidNull, Type[] constructorArgumentTypes)
        {
            this.stats.Selected(ConstructorCallTransformer.Get(constructor).ToString());

            PlanFilter f;

            if (forbidNull)
            {
                f = delegate(Plan p, int i)
                {
                    // Non-null heuristic
                    if (!constructorArgumentTypes[i].IsValueType && (p.transformer is PrimitiveValueTransformer))
                    {
                        return(false);
                    }

                    return(true);
                };
            }
            else
            {
                f = delegate(Plan p, int i)
                {
                    return(true);
                };
            }

            RandomPlansResult r;

            if (!RandomPlans(out r, constructorArgumentTypes, f, planManager.builderPlans, forbidNull, null))
            {
                stats.CreatedNew(CreationResult.NoInputs);
                return;
            }
            Plan plan = new Plan(ConstructorCallTransformer.Get(constructor),
                                 r.fplans, r.fparameterChoosers);

            plan.ClassName = constructor.DeclaringType.Name;

            planManager.AddMaybeExecutingIfNeeded(plan, this.stats);
        }