日期:2014-05-19  浏览次数:20948 次

我想要分析C#源文件,找出其中类的类名,字段名,方法名等,大家有什么好的建议
如题,谢谢!

------解决方案--------------------
static void Main(string[] args)
{

System.Reflection.Assembly assembly = System.Reflection.Assembly.LoadFile(
@ "C:\ConsoleApplication1\ClassLibrary1\bin\Debug\ClassLibrary1.dll ");
Type[] types = assembly.GetTypes();
foreach (Type type in types)
{
Console.WriteLine(type.Name);

System.Reflection.FieldInfo[] fis = type.GetFields();
foreach (System.Reflection.FieldInfo fi in fis)
{
Console.WriteLine(fi.Name);
}

//... 方法, 属性 类似
}

Console.ReadKey();

}
------解决方案--------------------
参考资料

1。编译原理
计算机系的教科书

2。C#语言式样
vs2005安装目录下\Microsoft Visual Studio 8\VC#\Specifications\1041
------解决方案--------------------
确实可以先编译再用反射 但这样肯定效率差 而且会得到许多不想要的东西
这个应该类似词法分析器 逐行读取 记录当前的namespace, class name, 并根据格式判断当前行是field 还是method 还是property 大概就这样吧
------解决方案--------------------

1.词法分析器 逐行读取 记录当前的namespace, class name, 并根据格式判断当前行是field 还是method 还是property

2.反射