Add() public method

A constructor which failed.
public Add ( ConstructorFailedReason reason ) : void
reason ConstructorFailedReason Why the constructor failed.
return void
Exemplo n.º 1
0
        /// <summary>
        /// Try to find a constructor by looking at the most specific first.
        /// </summary>
        /// <param name="concreteType">Type to create</param>
        /// <param name="constructor">Chosen constructor</param>
        /// <returns>Error if any; otherwise null.</returns>
        protected virtual FailureReasons TryGetConstructor(Type concreteType, out ConstructorInfo constructor)
        {
            var error = new FailureReasons(concreteType);

            foreach (var constructorInfo in concreteType.GetConstructors().OrderByDescending(x => x.GetParameters().Length))
            {
                var missing = FindMissingArgument(constructorInfo);
                if (missing == null)
                {
                    constructor = constructorInfo;
                    return(null);
                }

                error.Add(new ConstructorFailedReason(constructorInfo, missing.ParameterType));
            }

            constructor = null;
            return(error);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Try to find a constructor by looking at the most specific first.
        /// </summary>
        /// <param name="concreteType">Type to create</param>
        /// <param name="constructor">Chosen constructor</param>
        /// <returns>Error if any; otherwise null.</returns>
        protected virtual FailureReasons TryGetConstructor(Type concreteType, out ConstructorInfo constructor)
        {
            var error = new FailureReasons(concreteType);
            foreach (var constructorInfo in concreteType.GetConstructors().OrderByDescending(x => x.GetParameters().Length))
            {
                var missing =
                    constructorInfo.GetParameters().FirstOrDefault(
                        parameter => !_registrar.Registrations.Any(x => x.Implements(parameter.ParameterType)));

                if (missing == null)
                {
                    constructor = constructorInfo;
                    return null;
                }


                error.Add(new ConstructorFailedReason(constructorInfo, missing.ParameterType));
            }

            constructor = null;
            return error;
        }
        /// <summary>
        /// Try to find a constructor by looking at the most specific first.
        /// </summary>
        /// <param name="concreteType">Type to create</param>
        /// <param name="constructor">Chosen constructor</param>
        /// <returns>Error if any; otherwise null.</returns>
        protected virtual FailureReasons TryGetConstructor(Type concreteType, out ConstructorInfo constructor)
        {
            var error = new FailureReasons(concreteType);
            foreach (var constructorInfo in concreteType.GetConstructors().OrderByDescending(x => x.GetParameters().Length))
            {
                var missing = FindMissingArgument(constructorInfo);
                if (missing == null)
                {
                    constructor = constructorInfo;
                    return null;
                }

                error.Add(new ConstructorFailedReason(constructorInfo, missing.ParameterType));
            }

            constructor = null;
            return error;
        }