Beispiel #1
0
        protected override void TransformItems(CSharpCodeCompletionContext context, GroupedItemsCollector collector)
        {
            var referenceExpression = context.UnterminatedContext.ToReferenceExpression() ??
                                      context.TerminatedContext.ToReferenceExpression();

            if (referenceExpression == null)
            {
                return;
            }

            var settingsStore = referenceExpression.GetSettingsStore();

            if (!settingsStore.GetValue(PostfixTemplatesSettingsAccessor.ShowLengthCountItems))
            {
                return;
            }

            CSharpDeclaredElementInfo existingInfo = null;

            foreach (var lookupItem in collector.Items)
            {
                var aspectLookupItem = lookupItem as IAspectLookupItem <CSharpDeclaredElementInfo>;
                if (aspectLookupItem != null && IsLengthOrCountProperty(aspectLookupItem.Info))
                {
                    // do nothing if both 'Length' and 'Count' or multiple 'Length'/'Count' items exists
                    if (existingInfo != null)
                    {
                        return;
                    }

                    existingInfo = aspectLookupItem.Info;
                }
            }

            if (existingInfo != null)
            {
                var invertedInfo = new CSharpDeclaredElementInfo(
                    existingInfo.ShortName, existingInfo.PreferredDeclaredElement.NotNull(),
                    context.BasicContext.LookupItemsOwner, context, context.BasicContext);

                invertedInfo.Ranges    = context.CompletionRanges;
                invertedInfo.Placement = new LookupItemPlacement(InvertName(existingInfo));

                var invertedItem = LookupItemFactory.CreateLookupItem(invertedInfo)
                                   .WithPresentation(item => new InvertedItemPresentation(item.Info))
                                   .WithMatcher(item => new InvertedTextualMatcher(item.Info))
                                   .WithBehavior(item => new CSharpDeclaredElementBehavior <CSharpDeclaredElementInfo>(item.Info));

                collector.Add(invertedItem);
            }
        }
            public StaticMethodBehavior([NotNull] CSharpDeclaredElementInfo info) : base(info)
            {
                var instance = info.PreferredDeclaredElement;

                if (instance == null)
                {
                    return;
                }

                var method = instance.Element as IMethod;

                if (method != null)
                {
                    myMethods.Add(new DeclaredElementInstance <IMethod>(method, instance.Substitution));
                }
            }
Beispiel #3
0
 public InvertedTextualMatcher([NotNull] CSharpDeclaredElementInfo info)
 {
     myText = InvertName(info);
 }