Exemple #1
0
        public void Process(IBuildSession buildSession)
        {
            var unitUnderConstruction = buildSession.GetUnitUnderConstruction();
            var effectiveToken        = Equals(_token, Token.Propagate) ? unitUnderConstruction.Token : _token;

            var genericType = _redirectTo.MakeGenericType(buildSession.GetUnitUnderConstruction().GetUnitType().GetGenericArguments());

            buildSession.BuildResult = buildSession.BuildUnit(new UnitInfo(genericType, effectiveToken));
        }
Exemple #2
0
        public void Process(IBuildSession buildSession)
        {
            var unitType = buildSession.GetUnitUnderConstruction().GetUnitType();
            var ctor     = GetConstructor(unitType.GetConstructors());

            buildSession.BuildResult = new BuildResult(ctor);
        }
 public void Process(IBuildSession buildSession)
 {
     if (buildSession.GetUnitUnderConstruction().Id is ParameterInfo parameterInfo && parameterInfo.HasDefaultValue)
     {
         buildSession.BuildResult = new BuildResult(parameterInfo.DefaultValue);
     }
 }
        public void Process(IBuildSession buildSession)
        {
            if (!buildSession.BuildResult.HasValue)
            {
                var type = buildSession.GetUnitUnderConstruction().GetUnitType();

                // ReSharper disable once PossibleNullReferenceException
                if (!type.IsInterface && !type.IsAbstract)
                {
                    ConstructorInfo constructor;
                    using (Log.Block(LogLevel.Trace, "Looking for constructor"))
                    {
                        constructor = buildSession.GetConstructorOf(type);
                    }

                    var parameters = constructor.GetParameters();

                    if (parameters.Length == 0 && type.IsValueType) // do not create default value of value type, it can confuse logic
                    {
                        return;
                    }

                    try
                    {
                        object instance;
                        if (parameters.Length == 0)
                        {
                            instance = constructor.Invoke(EmptyArray <object> .Instance);
                        }
                        else
                        {
                            object[] valuesForParameters;
                            using (Log.Block(LogLevel.Trace, () => "Looking for parameters [" + string.Join(", ", parameters.Select(_ => _.ToString()).ToArray()) + "]"))
                            {
                                valuesForParameters = buildSession.GetValuesForParameters(parameters);
                            }

                            instance = constructor.Invoke(valuesForParameters);
                        }

                        buildSession.BuildResult = new BuildResult(instance);
                    }
                    catch (TargetInvocationException exception)
                    {
                        if (exception.InnerException == null)
                        {
                            throw;
                        }

                        // extract original exception from TargetInvocationException and throw it,
                        // store original stack trace as exception data since throwing will replace it
                        exception.InnerException.AddData(ExceptionData.TargetInvocationStackTrace, exception.StackTrace);
                        exception.InnerException.AddData(ExceptionData.OriginalStackTrace, exception.InnerException.StackTrace);
                        throw exception.InnerException;
                    }
                }
            }
        }
        public void Process(IBuildSession buildSession)
        {
            if (!buildSession.BuildResult.HasValue)
            {
                var unitUnderConstruction = buildSession.GetUnitUnderConstruction();
                var effectiveToken        = Equals(_token, Token.Propagate) ? unitUnderConstruction.Token : _token;

                var unitInfo = new UnitInfo(_redirectTo, effectiveToken);
                buildSession.BuildResult = buildSession.BuildUnit(unitInfo);
            }
        }
        public void Process(IBuildSession buildSession)
        {
            var propertyInfo = (PropertyInfo)buildSession.GetUnitUnderConstruction().Id;

            var attribute = propertyInfo
                            .GetCustomAttributes <InjectAttribute>()
                            .SingleOrDefault();

            if (attribute == null)
            {
                Log.WriteLine(LogLevel.Info, () => string.Format("{0}{{{1}}}", this, "No Property marked with InjectAttribute"));
            }
            else
            {
                var unitInfo = new UnitInfo(propertyInfo.PropertyType, attribute.InjectionPointId);
                buildSession.BuildResult = buildSession.BuildUnit(unitInfo);
            }
        }
Exemple #7
0
        public void Process(IBuildSession buildSession)
        {
            var unitType = buildSession.GetUnitUnderConstruction().GetUnitType();

            var properties =
                _names.Select(
                    name =>
            {
                var property = unitType.GetProperty(name);
                if (property == null)
                {
                    throw new ArmatureException(string.Format("There is no property {0} in type {1}", _names, unitType.ToLogString()));
                }

                return(property);
            })
                .ToArray();

            buildSession.BuildResult = new BuildResult(properties);
        }