public static IList <IDataSource> WithFilters( this IList <IDataSource> dataSources, IMemberMapperData mapperData) { var dataSourceCount = dataSources.Count; var filteredDataSources = new IDataSource[dataSourceCount]; for (var i = 0; i < dataSourceCount; ++i) { var dataSource = dataSources[i]; var filteredDataSource = filteredDataSources[i] = ApplyFilter( dataSource.IsFallback ? dataSources[i - 1].SourceMember : dataSource.SourceMember, dataSource, mapperData); if (!dataSource.IsFallback) { continue; } if (filteredDataSource != null) { break; } var filteredDataSourcesWithoutFallback = new IDataSource[dataSourceCount - 1]; filteredDataSourcesWithoutFallback.CopyFrom(filteredDataSources); return(filteredDataSourcesWithoutFallback); } return(filteredDataSources); }
private static bool TryAdjustToSingleUseableDataSource( ref IList <IDataSource> dataSources, IMemberMapperData mapperData) { var finalDataSource = dataSources.Last(); if (!finalDataSource.IsFallback) { return(false); } var finalValue = finalDataSource.Value; if (finalValue.NodeType == ExpressionType.Coalesce) { // Coalesce between the existing target member value and the fallback: dataSources[dataSources.Count - 1] = new AdHocDataSource( finalDataSource.SourceMember, ((BinaryExpression)finalValue).Right, finalDataSource.Condition, finalDataSource.Variables); return(false); } var targetMemberAccess = mapperData.GetTargetMemberAccess(); if (!ExpressionEvaluation.AreEqual(finalValue, targetMemberAccess)) { return(false); } if (dataSources.Count == 2) { return(true); } var dataSourcesWithoutFallback = new IDataSource[dataSources.Count - 1]; dataSourcesWithoutFallback.CopyFrom(dataSources); dataSources = dataSourcesWithoutFallback; return(false); }