/// <summary> /// Gets the number of parameters that the system recognizes /// </summary> /// <param name="Constructor">Constructor to check</param> /// <param name="MappingManager">Mapping manager</param> /// <returns>The number of parameters that it has knoweledge of</returns> private static int GetParameterCount(ConstructorInfo Constructor, MappingManager MappingManager) { int Count = 0; ParameterInfo[] Parameters = Constructor.GetParameters(); foreach (ParameterInfo Parameter in Parameters) { bool Inject = true; object[] Attributes = Parameter.GetCustomAttributes(false); if (Attributes.Length > 0) { foreach (Attribute Attribute in Attributes) { if (MappingManager.GetMapping(Parameter.ParameterType, Attribute.GetType()) != null) { ++Count; Inject = false; break; } } } if (Inject) { if (MappingManager.GetMapping(Parameter.ParameterType) != null) ++Count; } } if (Count == Parameters.Length) return Count; return int.MinValue; }
/// <summary> /// Chooses a constructor /// </summary> /// <param name="ImplementationType">Type of the class</param> /// <param name="MappingManager">Mapping manager</param> /// <returns>The most appropriate constructor</returns> public static ConstructorInfo ChooseConstructor(Type ImplementationType, MappingManager MappingManager) { ConstructorInfo[] Constructors = ImplementationType.GetConstructors(); int MaxValue = int.MinValue; ConstructorInfo CurrentConstructor = null; foreach (ConstructorInfo Constructor in Constructors) { int Count = GetParameterCount(Constructor, MappingManager); if (Count > MaxValue) { CurrentConstructor = Constructor; MaxValue = Count; } } return CurrentConstructor; }
/// <summary> /// Constructor /// </summary> /// <param name="ImplementationType">Implementation type</param> /// <param name="MappingManager">Mapping manager</param> public Standard(Type ImplementationType, MappingManager MappingManager) { this.ReturnType = ImplementationType; this.MappingManager = MappingManager; }