Пример #1
0
        public IEnumerable <ITypeDependencyObject> GetDependencyObjects(ITypeActivator runtimeTypeActivator, Type type, bool defaultTypeInstantiation, ITypeDependencyAttributeProvider typeDependencyAttributeProvider = null, ITypeInjectionAttributeProvider typeInjectionAttributeProvider = null)
        {
            var dependencyObjects = new List <ITypeDependencyObject>();
            var constructors      = type.GetConstructors();

            if (constructors.Length == 1)
            {
                var constructor           = constructors[0];
                var constructorParameters = constructor.GetParameters();
                if (constructorParameters.Length == 0)
                {
                    var injectionObjects = new List <ITypeInjectionObject>();
                    var constructorType  = constructor.DeclaringType;
                    var runtimeAttribute = type.GetAttribute <PropertyDependencyAttribute>(constructorType);
                    var properties       = type.GetProperties().Where((p) => !p.IsSpecialName && p.CanRead && p.CanWrite);
                    injectionObjects.AddRange(properties.Select((p) =>
                    {
                        var injectionObject = new TypeInjectionObject(runtimeTypeActivator, p.GetAttribute <PropertyInjectionAttribute>(p.PropertyType), p.PropertyType, defaultTypeInstantiation);
                        PropertyCache.SetPropertyInfo(injectionObject.RuntimeType, p);
                        return(injectionObject);
                    }));
                    var dependencyObject = new TypeDependencyObject(runtimeTypeActivator, runtimeAttribute, injectionObjects, constructorType, defaultTypeInstantiation);
                    dependencyObjects.Add(dependencyObject);
                }
            }
            return(dependencyObjects);
        }
Пример #2
0
        public IEnumerable <ITypeDependencyObject> GetDependencyObjects(ITypeActivator runtimeTypeActivator, Type type, bool defaultTypeInstantiation, ITypeDependencyAttributeProvider typeDependencyAttributeProvider = null, ITypeInjectionAttributeProvider typeInjectionAttributeProvider = null)
        {
            var dependencyObjects = new List <ITypeDependencyObject>();
            var constructors      = type.GetConstructors();

            if (constructors.Length == 0 && typeof(ValueType).IsAssignableFrom(type))
            {
                constructors = type.GetConstructors().ToArray();
                if (constructors.Length == 0)
                {
                    constructors = type.BaseType.GetConstructors().ToArray();
                }
                if (constructors.Length == 0)
                {
                    var dependencyAttribute = typeDependencyAttributeProvider.GetAttribute(type, type);
                    var injectionObjects    = new List <ITypeInjectionObject>(); // { new TypeInjectionObject(runtimeTypeActivator, null, null, defaultTypeInstantiation) };
                    var dependencyObject    = new TypeDependencyObject(runtimeTypeActivator, dependencyAttribute, injectionObjects, type, defaultTypeInstantiation);
                    dependencyObjects.Add(dependencyObject);
                }
                return(dependencyObjects);
            }
            foreach (var constructorInfo in constructors)
            {
                var dependencyAttribute = typeDependencyAttributeProvider.GetAttribute(constructorInfo, type);
                var injectionObjects    = constructorInfo.GetParameters().Select(p => (ITypeInjectionObject) new TypeInjectionObject(runtimeTypeActivator, typeInjectionAttributeProvider.GetAttribute(p, p.ParameterType), p.ParameterType, defaultTypeInstantiation));
                dependencyObjects.Add(new TypeDependencyObject(runtimeTypeActivator, dependencyAttribute, injectionObjects, type, defaultTypeInstantiation));
            }
            return(dependencyObjects);
        }
Пример #3
0
        public IEnumerable <ITypeDependencyObject> GetDependencyObjects(ITypeActivator runtimeTypeActivator, Type type, bool defaultTypeInstantiation, ITypeDependencyAttributeProvider typeDependencyAttributeProvider = null, ITypeInjectionAttributeProvider typeInjectionAttributeProvider = null)
        {
            var dependencyObjects = new List <ITypeDependencyObject>();

            foreach (var constructorInfo in type.GetMethods())
            {
                if (constructorInfo.Name == "Rule")
                {
                    var runtimeAttribute = constructorInfo.GetAttribute <InterfaceDependencyAttribute>(constructorInfo.ReturnType);
                    var injectionObjects = constructorInfo.GetParameters().Select(p => new TypeInjectionObject(runtimeTypeActivator, p.GetAttribute <InterfaceInjectionAttribute>(p.ParameterType), p.ParameterType, defaultTypeInstantiation));
                    dependencyObjects.Add(new TypeDependencyObject(runtimeTypeActivator, runtimeAttribute, injectionObjects, constructorInfo.ReturnType, defaultTypeInstantiation));
                }
            }
            return(dependencyObjects);
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TypeBuilder"/> class.
 /// </summary>
 /// <param name="typeConstructor">Type constructor</param>
 /// <param name="typeFilter">Type filter</param>
 /// <param name="typeParser">Type parser</param>
 /// <param name="typeResolver">Type resolver</param>
 public TypeBuilder(ITypeActivator typeActivator, ITypeConstructor typeConstructor, ITypeFilter typeFilter, ITypeParser typeParser, ITypeResolver typeResolver, ITypeDependencyAttributeProvider typeDependencyAttributeProvider = null, ITypeInjectionAttributeProvider typeInjectionAttributeProvider = null)
 {
     DependencyAttributeExtractor = typeDependencyAttributeProvider ?? throw new ArgumentNullException(nameof(typeDependencyAttributeProvider));
     InjectionAttributeExtractor  = typeInjectionAttributeProvider ?? throw new ArgumentNullException(nameof(typeInjectionAttributeProvider));
     Activator   = typeActivator ?? throw new ArgumentNullException(nameof(typeActivator));
     Constructor = typeConstructor ?? throw new ArgumentNullException(nameof(typeConstructor));
     Filter      = typeFilter ?? throw new ArgumentNullException(nameof(typeFilter));
     Resolver    = typeResolver ?? throw new ArgumentNullException(nameof(typeResolver));
     Parser      = typeParser ?? throw new ArgumentNullException(nameof(typeParser));
 }