Daniel
Daniel

Reputation: 16226

Get C# type from file name

I have a bunch of files in a directory:

Class1.ascx : contains class Class1
Class2.ascx : contains class Class2

I have a list of the file names, and I want to take each filename and identify the corresponding class.

foreach(var fileName in listOfFileNames)
{
   ...
   Type t = MagicMethod(fileName)
   ...
}

Anyone know what MagicMethod would look like or if it is even possible to do?

Upvotes: 0

Views: 336

Answers (1)

Gabriel McAdams
Gabriel McAdams

Reputation: 58293

The filename could be different than the classname. The file may not even contain a class.

You would have to parse the file.

Here is a parser on codeplex.

Upvotes: 6

Related Questions