예제 #1
0
        // TODO
        private static ConstructorDefImpl CreateConstructorDef(ConstructorInfo constructor, bool injectable)
        {
            var parameters = constructor.GetParameters();

            IConstructorArg[] args = new ConstructorArgImpl[parameters.Length];

            for (int i = 0; i < parameters.Length; i++)
            {
                // TODO for getInterfaceTarget() call
                Type type = parameters[i].ParameterType;
                type = ReflectionUtilities.EnsureInterfaceType(type);
                ////if (type.IsGenericType && type.FullName == null)
                ////{
                ////   type = type.GetGenericTypeDefinition();
                ////}
                bool isFuture;

                if (ReflectionUtilities.IsAssignableFromIgnoreGeneric(typeof(IInjectionFuture <>), type))
                {
                    type     = ReflectionUtilities.GetInterfaceTarget(typeof(IInjectionFuture <>), type);
                    isFuture = true;
                }
                else
                {
                    isFuture = false;
                }

                ParameterAttribute named = parameters[i].GetCustomAttribute <ParameterAttribute>();
                if (named != null && !injectable)
                {
                    Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException(constructor + " is not injectable, but it has an @Parameter annotation."), LOGGER);
                }

                if (type == null)
                {
                    Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new TangApplicationException("Exception"), LOGGER);
                }

                string typename = ReflectionUtilities.GetAssemblyQualifiedName(type);
                if (typename == null)
                {
                    typename = type.Name;
                }
                args[i] = new ConstructorArgImpl(typename, named == null ? null : ReflectionUtilities.GetAssemblyQualifiedName(named.Value), isFuture);
            }
            return(new ConstructorDefImpl(ReflectionUtilities.GetAssemblyQualifiedName(constructor.DeclaringType), args, injectable));
        }
예제 #2
0
        public override bool Equals(object o)
        {
            ConstructorArgImpl arg = (ConstructorArgImpl)o;

            if (!type.Equals(arg.type))
            {
                return(false);
            }
            if (name == null && arg.name == null)
            {
                return(true);
            }
            if (name == null && arg.name != null)
            {
                return(false);
            }
            if (name != null && arg.name == null)
            {
                return(false);
            }
            return(name.Equals(arg.name));
        }
예제 #3
0
        // TODO
        private static ConstructorDefImpl CreateConstructorDef(ConstructorInfo constructor, bool injectable)
        {
            var parameters = constructor.GetParameters();

            IConstructorArg[] args = new ConstructorArgImpl[parameters.Length];

            for (int i = 0; i < parameters.Length; i++)
            {
                // TODO for getInterfaceTarget() call
                Type type = parameters[i].ParameterType;
                type = ReflectionUtilities.EnsureInterfaceType(type);
                ////if (type.IsGenericType && type.FullName == null)
                ////{
                ////   type = type.GetGenericTypeDefinition();
                ////}
                bool isFuture;

                if (ReflectionUtilities.IsAssignableFromIgnoreGeneric(typeof(IInjectionFuture<>), type)) 
                {
                    type = ReflectionUtilities.GetInterfaceTarget(typeof(IInjectionFuture<>), type);
                    isFuture = true;
                } 
                else 
                {
                    isFuture = false;
                }

                ParameterAttribute named = parameters[i].GetCustomAttribute<ParameterAttribute>();
                if (named != null && !injectable)
                {
                    Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ClassHierarchyException(constructor + " is not injectable, but it has an @Parameter annotation."), LOGGER);
                }

                if (type == null)
                {
                    Org.Apache.REEF.Utilities.Diagnostics.Exceptions.Throw(new ApplicationException("Exception"), LOGGER);
                }

                string typename = ReflectionUtilities.GetAssemblyQualifiedName(type);
                if (typename == null)
                {
                    typename = type.Name;
                }
                args[i] = new ConstructorArgImpl(typename, named == null ? null : ReflectionUtilities.GetAssemblyQualifiedName(named.Value), isFuture);
            }
            return new ConstructorDefImpl(ReflectionUtilities.GetAssemblyQualifiedName(constructor.DeclaringType), args, injectable); 
        }