Ejemplo n.º 1
0
        protected override object InvokeFactoryMethod(Type type, string methodName, object[] args)
        {
            MethodInfo      factory = GetFactoryMethod(type, methodName, args, BF_AllStaticMembers);
            FactoryDelegate factoryDelegate;

            if (!FactoryDelegates.TryGetValue(factory, out factoryDelegate))
            {
                factoryDelegate = CreateFactoryDelegate(factory);
                FactoryDelegates.Add(factory, factoryDelegate);
            }
            return(factoryDelegate.Invoke(args));
        }
Ejemplo n.º 2
0
        /// <SecurityNote>
        /// Critical: Creates/accesses non-public accessors
        /// </SecurityNote>
        private object CreateInstanceWithCtor(Type type, object[] args)
        {
            ConstructorInfo ctor = null;

            if (args == null || args.Length == 0)
            {
                ctor = type.GetConstructor(BF_AllInstanceMembers, null, Type.EmptyTypes, null);
            }
            if (ctor == null)
            {
                // We go down this path even if there are no args, because we might match a params array
                ConstructorInfo[] ctors = type.GetConstructors(BF_AllInstanceMembers);
                // This method throws if it can't find a match, so ctor will never be null
                ctor = (ConstructorInfo)BindToMethod(BF_AllInstanceMembers, ctors, args);
            }
            FactoryDelegate factoryDelegate;

            if (!FactoryDelegates.TryGetValue(ctor, out factoryDelegate))
            {
                factoryDelegate = CreateFactoryDelegate(ctor);
                FactoryDelegates.Add(ctor, factoryDelegate);
            }
            return(factoryDelegate.Invoke(args));
        }