Пример #1
0
        public InheritanceMarginTag(Workspace workspace, int lineNumber, ImmutableArray <InheritanceMarginItem> membersOnLine)
        {
            Contract.ThrowIfTrue(membersOnLine.IsEmpty);

            Workspace     = workspace;
            LineNumber    = lineNumber;
            MembersOnLine = membersOnLine;
            // The common case, one line has one member, avoid to use select & aggregate
            if (membersOnLine.Length == 1)
            {
                var member       = membersOnLine[0];
                var targets      = member.TargetItems;
                var relationship = targets[0].RelationToMember;
                foreach (var target in targets.Skip(1))
                {
                    relationship |= target.RelationToMember;
                }

                Moniker = InheritanceMarginHelpers.GetMoniker(relationship);
            }
            else
            {
                // Multiple members on same line.
                var aggregateRelationship = membersOnLine
                                            .SelectMany(member => member.TargetItems.Select(target => target.RelationToMember))
                                            .Aggregate((r1, r2) => r1 | r2);
                Moniker = InheritanceMarginHelpers.GetMoniker(aggregateRelationship);
            }
        }
        public InheritanceMarginTag(Workspace workspace, int lineNumber, ImmutableArray <InheritanceMarginItem> membersOnLine)
        {
            Contract.ThrowIfTrue(membersOnLine.IsEmpty);

            Workspace     = workspace;
            LineNumber    = lineNumber;
            MembersOnLine = membersOnLine;

            // The common case is that one line has one member.
            using var _ = ArrayBuilder <InheritanceTargetItem> .GetInstance(out var allItems);

            foreach (var marginItem in membersOnLine)
            {
                allItems.AddRange(marginItem.TargetItems);
            }

            var relationship = allItems[0].RelationToMember;

            for (var i = 1; i < allItems.Count; i++)
            {
                relationship |= allItems[i].RelationToMember;
            }

            Moniker = InheritanceMarginHelpers.GetMoniker(relationship);
        }