using ICSharpCode.NRefactory.CSharp; // create a new CSharpProject CSharpProject project = new CSharpProject(); // add a new source code file to the project project.AddFile("Class1.cs", "public class Class1 {}"); // get the contents of the System namespace INamespaceContents nsContents = project.GetNamespaceContents("System"); // iterate over the contents of the namespace and print the names of all classes foreach (IEntity entity in nsContents.Types) { Console.WriteLine(entity.Name); }
using ICSharpCode.NRefactory.CSharp; // create a new CSharpProject CSharpProject project = new CSharpProject(); // add a new source code file to the project project.AddFile("Class1.cs", "namespace MyNamespace { public class Class1 {} }"); // get the contents of the MyNamespace namespace INamespaceContents nsContents = project.GetNamespaceContents("MyNamespace"); // iterate over the contents of the namespace and print the names of all classes foreach (IEntity entity in nsContents.Types) { Console.WriteLine(entity.Name); }In this example, we create a new CSharpProject instance, add a new source code file to the project with a namespace of "MyNamespace", and then retrieve the contents of the "MyNamespace" namespace. Finally, we iterate over the classes in the namespace and print their names. The package library in use in these examples is ICSharpCode.NRefactory.CSharp, a C# code analysis library.