Esempio n. 1
0
        public virtual object CreateInstance(Type type,
                                             IEnumerable <KeyValuePair <string, object> > values = null,
                                             IServiceProvider serviceProvider = null,
                                             params Attribute[] attributes)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            try {
                ServiceProvider.PushCurrent(serviceProvider);
                serviceProvider = serviceProvider ?? ServiceProvider.Root;
                type            = GetActivationType(type);
                object result = ActivateCoreHelper(type, ref values, serviceProvider);
                if (result == null)
                {
                    throw RuntimeFailure.CannotActivateNoConstructor("type", type);
                }

                InitializeCoreHelper(result, type, values, serviceProvider);
                return(result);
            } finally {
                ServiceProvider.PopCurrent();
            }
        }