0

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.

Otiel
  • 18,404
  • 16
  • 78
  • 126
Sinatr
  • 20,892
  • 15
  • 90
  • 319
  • 1
    [MSDN Statement Keywords](http://msdn.microsoft.com/en-us/library/xt4z8b0f.aspx). As for your "more hard question", you could reflect the included files and see what types/functions are included in them (I have no idea if that's what you really want to do, though...). As for your last question, "how to make my own IntelliSence", that's WAY too broad a question for SO. – tnw Jul 29 '13 at 13:57
  • 2
    For the operands, the easiest solution is probably to hardcode them (there aren't that many). For the function definitions, you'll probably need to write a parser to read included files and search them for functions, which is a lot of work. – IanPudney Jul 29 '13 at 13:58
  • 1
    Use Roslyn to do this. Vote to close as duplicate of [Built-in C#/VB.Net editor with intellisense - Roslyn, VSTA, or something else?](http://stackoverflow.com/questions/12818041/built-in-c-vb-net-editor-with-intellisense-roslyn-vsta-or-something-else) – jason Jul 29 '13 at 14:00
  • It's a pretty huge effort that you are taking ;) IMO Roslyn is your best bet: http://msdn.microsoft.com/en-us/vstudio/roslyn.aspx – Antonio Bakula Jul 29 '13 at 14:04
  • Sorry, was away until now. I hear about Roslyn (VSTA?) first time. Could you possibly provide a simple example or at least what to look for, to have syntax highlighting. I don't need much else functionality apart from that and Roslyn looks to me as an overkill. Also questions about redistribution (what should be included, is it free, etc). I tend to use specialized solutions and I like when I actually making them. Using of library gives you what you need, but you still have no idea of how is it done. I know about `@` and it's relatively easy to check. Hardcoding operands I already mentioned. – Sinatr Jul 31 '13 at 06:57
  • It's unclear to me, why is it on hold and why is it down-voted. Ok, maybe I didn't put enough effort into my english skills or formatting, but find please "list of operands" subj question here. Other questions are just related (shall I spam separate questions for them?), my primary objective was an easy way of getting the list. Seems hardcoding is the **only** way (or using someone's library with again hardcoded list). – Sinatr Jul 31 '13 at 07:25

3 Answers3

5

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".

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • ಠ_ಠ Since you're poking around right now, instead of wasting your time acting like a search engine for folks, [take a look at this guy's question](http://stackoverflow.com/questions/17926186/byte-array-union-overlay-in-c-sharp-structlayout-explicit). You might be his only hope. –  Jul 29 '13 at 14:08
  • Thanks. So hardcoded list of operands, generated list of functions and some checks (for `@` and strings) is the way to go it seems. I don't expect complicated or advanced coding from the user. I just want to make something looking nicer than plain text. – Sinatr Jul 31 '13 at 07:16
  • Getting list with `AppDomain.CurrentDomain.GetAssemblies()`, `...GetTypes()`, `...GetMethods()` loops seems will do a trick, thanks. There are, however, some garbage-looking types and method names, but I should figure out how to filter those. Thanks. – Sinatr Jul 31 '13 at 07:28
2

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.
Tim S.
  • 55,448
  • 7
  • 96
  • 122
  • Creating a hardcoded list of Net Framework class library is possible, but would be too much. =D I should rather take this list programmatically. – Sinatr Jul 31 '13 at 07:18
0

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

See:

for reference.

Another possible choice is NRefactory:

Konrad Morawski
  • 8,307
  • 7
  • 53
  • 91
  • Thanks, but those 2 are overkills. They are huge specialized libraries and I only need syntax highlightning. – Sinatr Jul 31 '13 at 07:21