简体   繁体   English

从文件名获取C#类型

[英]Get C# type from file name

I have a bunch of files in a directory: 我在目录中有一堆文件:

Class1.ascx : contains class Class1 Class1.ascx :包含类Class1
Class2.ascx : contains class Class2 Class2.ascx :包含类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? 有人知道MagicMethod会是什么样子,或者甚至可以做到吗?

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 . 这是codeplex上的解析器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM