3

I am implementing a syntax highlighter using C# windows forms, and would like to get a list of all names, I know that this should be done manually, adding keywords and names but i was wondering if there is a function in C# that could help me do this.

yahya kh
  • 751
  • 3
  • 11
  • 23
  • 1
    What are "_C# Classes Names_"? Can you provide an example, maybe with pseudo code to show what you need? – Tim Schmelter Jun 06 '12 at 07:58
  • Like DataTable, ViewState, GridView, .............etc. – yahya kh Jun 06 '12 at 07:59
  • So you need to show the class' name in a syntax highlighter when the user enters the class' name?? What are you really trying to achieve? – Tim Schmelter Jun 06 '12 at 08:02
  • _"I am implementing a syntax highlighter using C# windows forms"_ Why don't you write a Visual Studio extension? It's a lot easier than building your own syntax highlighter. – CodeCaster Jun 06 '12 at 08:03
  • Can you explain "CodeCaster", i am trying to do something like this http://stackoverflow.com/questions/10892884/formating-c-sharp-code-in-text. – yahya kh Jun 06 '12 at 08:05
  • I think a syntax highlighter is based on the syntax: so instead of hardcoding class names, you might just want to know when to expect one, and highlight accordingly? – Nanne Jun 06 '12 at 08:06

4 Answers4

4

Use reflection.

Assembly.GetAssembly(typeof(MyClass)).GetTypes()
UBCoder
  • 659
  • 1
  • 6
  • 7
3

You will have to use the reflection to get the names of classes in a dll.

// Using Reflection to get information from an Assembly:
System.Reflection.Assembly o = System.Reflection.Assembly.Load("mscorlib.dll");
var types = o.GetTypes();
Asif Mushtaq
  • 13,010
  • 3
  • 33
  • 42
2
  Assembly asm = Assembly.GetExecutingAssembly();
  List<string> namespaceList = new List<string>();
  List<string> returnList = new List<string>();
  foreach (Type type in asm.GetTypes())
{
    if (type.Namespace == nameSpace)
        namespaceList.Add(type.Name);
}
    foreach (String className in namespaceList)
    returnList.Add(className);
    return returnList;
Rachana
  • 121
  • 1
  • 9
1

You can get the list for all assemblies in C#.NET using reflection.

Example :

Assembly mscorlib = typeof(string).Assembly;
foreach (Type type in mscorlib.GetTypes())
{
    Console.WriteLine(type.FullName);
}
Rajesh Subramanian
  • 6,400
  • 5
  • 29
  • 42