using System; using Mono.CSharp; var code = "System.Console.WriteLine(\"Hello, world!\");"; var settings = new CompilerSettings(); var evaluator = new Evaluator(settings); var syntaxTree = evaluator.Parse(code); var expression = syntaxTree.GetRoot().ChildNodes[0].Expression; if (expression is FullNamedExpression fullName) { Console.WriteLine(fullName.FullName); }
using System.Collections.Generic; using Mono.CSharp; var code = "ListIn this example, we are using FullNamedExpression to get the full name of the `List` class, which is in the `System.Collections.Generic` namespace. These code examples are part of the Mono.CSharp package library.numbers = new List ();"; var settings = new CompilerSettings(); var evaluator = new Evaluator(settings); var syntaxTree = evaluator.Parse(code); var expression = syntaxTree.GetRoot().ChildNodes[0].Expression; if (expression is ObjectCreateExpression objCreate) { var typeName = objCreate.TypeName; if (typeName is FullNamedExpression fullName) { Console.WriteLine(fullName.FullName); } }