示例#1
0
 internal static void IsNotAnAmbiguousType(Type type, string paramName)
 {
     if (Helpers.IsAmbiguousType(type))
     {
         throw new ArgumentException(StringResources.TypeIsAmbiguous(type), paramName);
     }
 }
        private InstanceProducer TryBuildArrayInstanceProducer(Type serviceType)
        {
            if (serviceType.IsArray)
            {
                Type elementType = serviceType.GetElementType();

                // We don't auto-register collections for ambiguous types.
                if (elementType.IsValueType || Helpers.IsAmbiguousType(elementType))
                {
                    return(null);
                }

                bool isContainerControlledCollection =
                    this.GetAllInstances(elementType) is IContainerControlledCollection;

                if (isContainerControlledCollection)
                {
                    return(this.BuildArrayProducerFromControlledCollection(serviceType, elementType));
                }
                else
                {
                    return(this.BuildArrayProducerFromUncontrolledCollection(serviceType, elementType));
                }
            }

            return(null);
        }
        private static bool IsGenericCollectionType(Type serviceType)
        {
            if (!serviceType.IsGenericType)
            {
                return(false);
            }

            Type[] arguments = serviceType.GetGenericArguments();

            // IEnumerable<T>, IList<T>, ICollection<T>, IReadOnlyCollection<T> and IReadOnlyList<T> are supported.
            if (serviceType.ContainsGenericParameters || arguments.Length != 1)
            {
                return(false);
            }

            Type elementType = arguments.First();

            // We don't auto-register collections for ambiguous types.
            if (elementType.IsValueType || Helpers.IsAmbiguousType(elementType))
            {
                return(false);
            }

            return(true);
        }
 private PropertyInfo[] GetInjectableProperties()
 {
     return((
                from property in this.Type.GetProperties()
                where property.CanWrite && property.GetSetMethod() != null
                where !property.PropertyType.IsValueType && !Helpers.IsAmbiguousType(property.PropertyType)
                where this.container.GetRegistration(property.PropertyType) != null
                select property)
            .ToArray());
 }