public Add ( |
||
reason | Why the constructor failed. | |
return | void |
/// <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); }
/// <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; }