protected IEnumerable <TModel> FindSuitable <TMemberInfo, TModel>( CompositeModel compositeModel, AbstractInjectableModel model, String name, Type declaringType, Func <CompositeMethodModel, TModel> methodModelGetter, Type targetType, Func <TMemberInfo, Type> memberInfoTargetTypeGetter ) where TMemberInfo : MemberInfo where TModel : AbstractMemberInfoModel <TMemberInfo> { // Type mixinDeclaringType = model is ParameterModel ? ( (ParameterModel) model ).NativeInfo.Member.DeclaringType : ( (FieldModel) model ).NativeInfo.DeclaringType; return(compositeModel.Methods .Select(method => methodModelGetter(method)) .Where(targetModel => targetModel != null) .Distinct() .Where(targetModel => (name == null || name.Equals(targetModel.NativeInfo.Name)) && (declaringType == null || declaringType.Equals(targetModel.NativeInfo.DeclaringType.GetGenericDefinitionIfContainsGenericParameters())) && (targetType == null || ReflectionHelper.AreStructurallySame(targetType, memberInfoTargetTypeGetter(targetModel.NativeInfo), true)) )); }
private static Tuple <Type, Type> FindImplementingTypeFrom( Type type, IEnumerable <Type> typesToSearch ) { return(type.GetAllParentTypes() .Select(t => Tuple.Create(t, typesToSearch.SelectMany(tt => tt.GetAllParentTypes()).FirstOrDefault(tt => ReflectionHelper.AreStructurallySame(t, tt, true)))) .Where(tuple => tuple.Item2 != null) .GetBottomTypes(tuple => tuple.Item1) .FirstOrDefault()); }