コード例 #1
0
        private ItemMatch <T1, T2> Append <T>(ItemMatch <T1, T2> match)
        {
            // Given the generics it very difficult to reduce duplication further here.
            if (typeof(T) == typeof(T1) && EqualityComparer <T1> .Default.Equals(match.Result1, default(T1)))
            {
                var item2Id = ChannelConfig.Type2EndpointConfiguration.TypeConfig.IdExtractor(match.Result2);
                var result1 = ChannelConfig.Type1EndpointConfiguration.Endpoint.Read(item2Id);
                if (!EqualityComparer <T1> .Default.Equals(result1, default(T1)))
                {
                    return(new ItemMatch <T1, T2>(result1, match.Result2));
                }
            }

            if (typeof(T) == typeof(T2) && EqualityComparer <T2> .Default.Equals(match.Result2, default(T2)))
            {
                var itemId  = ChannelConfig.Type1EndpointConfiguration.TypeConfig.IdExtractor(match.Result1);
                var result2 = ChannelConfig.Type2EndpointConfiguration.Endpoint.Read(itemId);
                if (!EqualityComparer <T2> .Default.Equals(result2, default(T2)))
                {
                    return(new ItemMatch <T1, T2>(match.Result1, result2));
                }
            }

            return(match);
        }
コード例 #2
0
        public ItemMatch <T1, T2> Complete(ItemMatch <T1, T2> itemMatch)
        {
            if (itemMatch.IsComplete)
            {
                return(itemMatch);
            }

            if (_completionSourceType == TargetType.T1 && itemMatch.Result1 == null)
            {
                var result2Id =
                    _channelConfiguration.Type2EndpointConfiguration.TypeConfig.IdExtractor(itemMatch.Result2);
                var oppositeItem = _channelConfiguration.Type1EndpointConfiguration.Endpoint.Read(result2Id);
                return(new ItemMatch <T1, T2>(oppositeItem, itemMatch.Result2));
            }

            if (_completionSourceType == TargetType.T2 && itemMatch.Result2 == null)
            {
                var result1Id =
                    _channelConfiguration.Type1EndpointConfiguration.TypeConfig.IdExtractor(itemMatch.Result1);
                var oppositeItem = _channelConfiguration.Type2EndpointConfiguration.Endpoint.Read(result1Id);
                return(new ItemMatch <T1, T2>(itemMatch.Result1, oppositeItem));
            }

            // Expecting not to even this this.
            return(itemMatch);
        }
コード例 #3
0
        public ItemMatch <T1, T2> AppendIndividualItem([NotNull] ItemMatch <T1, T2> initial, TargetType appendType = TargetType.T1)
        {
            if (initial == null)
            {
                throw new ArgumentNullException(nameof(initial));
            }

            if (initial.IsComplete)
            {
                return(initial);
            }

            if (appendType == TargetType.T1)
            {
                return(Append <T1>(initial));
            }

            return(Append <T2>(initial));
        }