Exemplo n.º 1
0
        public static IActivationStrategy CreateTypeActivator(Type type,
                                                              Func <IList <ConstructorInfo>, IActivationStrategy> constructorSelector)
        {
            ActivatableTypesPolicy.ThrowIfNotActivatable(type);
            var list = SortedConstructorList(type);

            if (list.Count < 1)
            {
                throw new IocException("Could not find any constructors for " + type.Name);
            }
            return(constructorSelector(list));
        }
        private Type?ApplyConvention(Type source)
        {
            var match = Regex.Match(source.FullName ?? "Not a real Type", @"^(.+[\.\+])I([^\.\+]+)$");

            if (!match.Success)
            {
                return(null);
            }
            var target = source.Assembly.GetType(match.Groups[1].Value + match.Groups[2].Value);

            if (target == null)
            {
                return(null);
            }
            if (!source.IsAssignableFrom(target))
            {
                return(null);
            }
            if (!ActivatableTypesPolicy.IsActivatable(target))
            {
                return(null);
            }
            return(target);
        }