I'm trying to add Intellisense to C# code editor based on the richtextbox control. So far, I've got it parsing the entered text to find all variables and their types (works well). The drop down box works well. What I can't get is a proper list of options for the drop-down list box.
How can I get the following list, programmatically:
I have already compiled a list of variables and their types, so when the user presses .
I know that I have a variable c
of type Color
. I just need to know what function to call to get the list I need for the drop-down box.
I've tried this code: http://www.codeproject.com/KB/cs/diy-intellisense.aspx but couldn't get it to work properly. I've also read a ton of other threads on StackOverflow to no avail. I'd really like to finish this instead of using someone elses drop-in editor component.
Any hints would be appreciated. Thanks.
To access this options page, choose Tools > Options, and then choose Text Editor > C# > IntelliSense.
Please try: Go to Visual Studio Installer, click Modify , uncheck IntelliCode in Individual components, then click Modify button to save the change, wait for the installation to complete, and then reinstall IntelliCode . In Visual Studio, go to Tools->Options->IntelliCode to check if the setting is Default.
Powered by a TypeScript based language service, Visual Studio delivers richer IntelliSense, support for modern JavaScript features, and improved productivity features such as Go to Definition, refactoring, and more.
You can enable or disable particular IntelliSense features in the Options dialog box, under Text Editor > C/C++ > Advanced. To configure IntelliSense for single files that aren't part of a project, look for the IntelliSense and browsing for non-project files section.
If you know the type, you should be able to Reflect on the type and get all the information you need.
Type.GetMembers would probably be your best bet. You may need a second call to get any static methods as well:
var instanceMembers = typeof(Color)
.GetMembers(BindingFlags.Instance | BindingFlags.Public);
var staticMembers = typeof(Color)
.GetMembers(BindingFlags.Static | BindingFlags.Public);
Each MemberInfo object will be able to tell you the MemberType (Property, Field, Method, Event, etc.)
Just use the instanceMembers
when the user types a variable (like c
in your example) followed by .
and use the staticMembers
when the user types a type name (like Color
in your example) followed by .
.
Assuming you have a name table with types this should give you a decent start:
var type = _names[name].Type;
var members = type.GetMembers(); // Check context to grab private methods?
So maybe you can extend your name table to include:
Type
Context
Members
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With