Question

Very simple question: how to get a list of all operands in the C#? Example:

{ "return", "break", "if", "case", "switch", ... };

More hard question: how to get a list of ALL functions (types, methods)?

{ "string", "Math.Abs", "double.IsNaN", "int.ToString", ... };

I want to make something like IntelliSense (a very poor and dirty one) for CodeDom. So the user can extend functionality of the software by adding his code into mine as text. I supply him a function body with certain arguments which he can use, but he also should be able to use any standard function, to example, double.ToString() or Math.PI. He enters his code into RichTextEditor. And I want to make it easier for him to see the syntax (highlighting known operands, opening/closing brackets, function parameters).

I can already highlight words (parameters) and it looks nice, but would be cool to highlight everything. And I see it as getting list of operands/functins/types/methods, which I have not idea of how to do (I can type in all operands into arrays myself ofc).

Should this question be rephrased: how to make my own IntelliSense? :-)

P.S.: a quick lurking haven't provide me with even a single result and I actually having the problem to formulate that what I am looking for.

Was it helpful?

Solution

For the keywords, you would go to the specification or MSDN; for example here - although IIRC there are a few obscure omissions. Note that many keywords are contextual (meaning: they may not always be keywords), and that keywords can be escaped (string @int = "evil";).

For "ALL functions"... well, there's assembly.GetTypes(), type.GetMethods(), etc. That and "loop".

OTHER TIPS

There's two things you're asking about:

  1. C# Keywords - these are things like int, return, break, and string - a list is available at the C# documentation.
  2. .Net Classes - these are things like Int32, Math, and String - a list is available at the C# documentation.

This is heavy-weight, but you might take a look at Project Roslyn.

See:

for reference.

Another possible choice is NRefactory:

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top