[Mono-dev] Utilizing the C# Parser

lukas einkemmer lukas.einkemmer at gmx.at
Thu Feb 2 17:19:15 EST 2006


Hi

I want to use the mono C# Parser to get information about class stucture
etc. in a project.

When I add the mcs.exe as an assembly reference and compile the following 
code

string []x = {"test.cs"};
Driver.Main(x);

i get a test.exe so it works.

But now I want to get the information about classes their methodes etc.
I looked through the mcs source code

 
SourceFile file = new SourceFile(fileName, path, 1);

input = File.OpenRead(file.Name);
SeekableStreamReader reader0 = new SeekableStreamReader(input,
Encoding.Default);
Tokenizer lexer = new Tokenizer(reader0, file, new ArrayList());
input.Close();

CSharpParser parser;
            
input = File.OpenRead(file.Name);
SeekableStreamReader reader = new SeekableStreamReader(input,
Encoding.Default);
reader.Position = 0;
parser = new CSharpParser(reader, file, new ArrayList());
parser.parse();
input.Close();
            
RootContext.ResolveTree();   //Exception here
RootContext.PopulateTypes();
RootContext.DefineTypes();
            

I get an System.NullReferenceException in TypeContainer.DefineType()
so I think I forgot to initialize something.

I dont need to create an .exe or .dll assembly I just want the informationen
about the source file regarding namespaces, classes, methodes,....

If anyone has done this before please give me a hint.

thx
Lukas

-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner



More information about the Mono-devel-list mailing list