大体意思是:
给你一个cs(C#)文件,这是一个类文件,编程实现: 0.找出该CS文件中的所有类
1.找到该类中的所有方法、包括方法的属性,参数等
2.找到该类的全局变量,包括类型
3.找到该类的父类(如果有的话)
4.统计注释行数(暂可以不考虑)
5.局部变量(暂可以不考虑)
例如:test.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;namespace CJStack
{
public partial class Form1 : Form
{
public ArrayList stack = new ArrayList();
public Graphics g ;
public Stack stackinout;
int x = 0;
/********************************************
* 用stack变量的入栈出栈:
* stackinout.push(string)这是入栈
* stackinout.pop(string)这是出栈,返回栈顶元素,并移除
* 此题中没用stack型变量,而是用了Arraylist型数组,目的是方便画图和刷新
********************************************/
private void button1_Click(object sender, EventArgs e)
{
int len = stack.Count;
stack.Add(textBox1.Text);
string s1 = textBox1.Text;
block(s1);
textBox1.Text = "";
textBox3.Text = stack.Count.ToString();
}
//绘制进栈的元素,把元素放到block中
public void block(string str)
{
g = CreateGraphics();
g.FillRectangle(new SolidBrush(Color.Purple), 300, 310-x, 100, 35);
g.DrawString(str, new Font("宋体", 14), new SolidBrush(Color.Black), new Point(305, 310-x+2));
x += 37;
}
private void button2_Click(object sender, EventArgs e)
{
int lenth = stack.Count;
if (lenth ==0)
MessageBox.Show("此栈已空");
else
{
textBox2.Text = stack[lenth - 1].ToString();
stack.RemoveAt(lenth - 1);
textBox3.Text = stack.Count.ToString();
x = 0;
if (stack.Count >= 0)
g.Clear(BackColor);
for (int i = 0; i < stack.Count; i++)
block(stack[i].ToString());
}
Form1_Load(sender, e);
}
}通过程序得出:
public partial class Form1
父类:Form
类中方法:
private void button1_Click(object sender, EventArgs e)
public void block(string str)
private void button2_Click(object sender, EventArgs e)
全局变量
public ArrayList stack = new ArrayList();
public Graphics g ;
public Stack stackinout;
int x = 0;
局部变量
麻烦大家说说自己的意见,大家共同探讨下。另外程序比较急,先谢谢大家了。
给你一个cs(C#)文件,这是一个类文件,编程实现: 0.找出该CS文件中的所有类
1.找到该类中的所有方法、包括方法的属性,参数等
2.找到该类的全局变量,包括类型
3.找到该类的父类(如果有的话)
4.统计注释行数(暂可以不考虑)
5.局部变量(暂可以不考虑)
例如:test.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;namespace CJStack
{
public partial class Form1 : Form
{
public ArrayList stack = new ArrayList();
public Graphics g ;
public Stack stackinout;
int x = 0;
/********************************************
* 用stack变量的入栈出栈:
* stackinout.push(string)这是入栈
* stackinout.pop(string)这是出栈,返回栈顶元素,并移除
* 此题中没用stack型变量,而是用了Arraylist型数组,目的是方便画图和刷新
********************************************/
private void button1_Click(object sender, EventArgs e)
{
int len = stack.Count;
stack.Add(textBox1.Text);
string s1 = textBox1.Text;
block(s1);
textBox1.Text = "";
textBox3.Text = stack.Count.ToString();
}
//绘制进栈的元素,把元素放到block中
public void block(string str)
{
g = CreateGraphics();
g.FillRectangle(new SolidBrush(Color.Purple), 300, 310-x, 100, 35);
g.DrawString(str, new Font("宋体", 14), new SolidBrush(Color.Black), new Point(305, 310-x+2));
x += 37;
}
private void button2_Click(object sender, EventArgs e)
{
int lenth = stack.Count;
if (lenth ==0)
MessageBox.Show("此栈已空");
else
{
textBox2.Text = stack[lenth - 1].ToString();
stack.RemoveAt(lenth - 1);
textBox3.Text = stack.Count.ToString();
x = 0;
if (stack.Count >= 0)
g.Clear(BackColor);
for (int i = 0; i < stack.Count; i++)
block(stack[i].ToString());
}
Form1_Load(sender, e);
}
}通过程序得出:
public partial class Form1
父类:Form
类中方法:
private void button1_Click(object sender, EventArgs e)
public void block(string str)
private void button2_Click(object sender, EventArgs e)
全局变量
public ArrayList stack = new ArrayList();
public Graphics g ;
public Stack stackinout;
int x = 0;
局部变量
麻烦大家说说自己的意见,大家共同探讨下。另外程序比较急,先谢谢大家了。
解决方案 »
- 应 PASV 命令的请求,服务器返回了一个与 FTP 连接地址不同的地址。
- 一个奇怪的想法,谁来解惑呢?
- 在WEB窗体下有没有像WINDOWS窗体下跟DateTimePicker一样的日期/时间控件啊?
- unix 系统中 连接access数据库的问题, 请大家帮忙看看, 顶者有分!!
- 在 ADO 编程中如何捕获外键约束异常
- 请问大家几个通过窗体认证的问题.100分相送.
- 请教:如何新建asp.net application web application
- 初學者的問題 各位大哥幫忙解決一下
- 我裝的VS.NET2005 BETA2的NET2.0 FRAMEWORK為什麽沒有System.Media的名字空間???導致101c#SAMCOLE中的PLAY SOUND示例不能運行?
- 在C#中调用mediaPlayer 9控件,怎么播放视频?
- 数据库 .net 程序跪求中
- 编辑TreeView节点标签文本时,如何实现文本的复制剪切粘贴?
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace Class_Reverse
{
class CJ
{
public string str = "";
public Array alist;
/*声明了连个全局变量*/
/*
*以下是这个类的所有方法
*
*/
public void funone() //第一个类不带参数的
{
int i = 0;
float j = 100;
//声明了两个局部变量
string filePath="F://C#//Jackchain";
} /// <summary>
/// 声明了一个带string返回值的类型
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public string FunSecond(string id)
{
return id;
} void FunThrid()
{
FunSecond("1");//调用第二个函数
} //这个类结束
} //一个新的类开始了
public class Jackchain : CJ //假设他继承父类Jackchain
{
public int a = 0;
int Jackchain_one()
{
return a;
}
private void Jackchain_Two(string x)
{
string str = a;
}
public static string Jackchain_Third()
{
return "I am Able!";
}
//这个类就到这里吧,结束了
}
}
解析后:class CJ
{
public string str = "";
public Array alist;
public void funone()
{
int i = 0;
float j = 100;
}
public string FunSecond(string id)
{
return id;
}
void FunThrid()
{
FunSecond("1");
}
}
public class Jackchain : CJ
{
public int a = 0;
int Jackchain_one()
{
return a;
}
private void Jackchain_Two(string x)
{
string str = a;
}
public static string Jackchain_Third()
{
return "I am Able!";
}
}
自己顶!!!
恩,不过我用过codedom生成代码,没用过codedom分析代码,能行不能行不知道哈哈,听说很强大
但是VS可以帮你做到你要的一切
看看
http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/5e2c5d94-b90f-45a4-bff1-e888ecd1afb5/
http://www.codecomments.com/archive358-2006-2-807130.html
或者给个例子反射能解析java的类吗?
第1个类
类:CJ 类型为:方法:funone 返回类型:void 方法类型:public 参数:()
方法:FunSecond 返回类型:string 方法类型:public 参数:(string id)方法:FunThrid 返回类型:void 方法类型: 参数:()
第2个类
类:Jackchain 的父类: CJ 类型为:public
方法:Jackchain_one 返回类型:int 方法类型: 参数:()方法:Jackchain_Two 返回类型:void 方法类型:private 参数:(string x)方法:Jackchain_Third 返回类型:string 方法类型:public static 参数:()
{
class Class1
{
[STAThread]
static void Main (string [ ] args)
{
System.Console.WriteLine(“列出程序集中的所有类型”);
Assembly a = Assembly.LoadFrom (“ReflectionExample.exe”);
Type[ ] mytypes = a.GetTypes( );
Foreach (Type t in mytypes)
{
System.Console.WriteLine ( t.Name );
}
System.Console.ReadLine ( );
System.Console.WriteLine (“列出HellWord中的所有方法” );
Type ht = typeof(HelloWorld);
MethodInfo[] mif = ht.GetMethods();
foreach(MethodInfo mf in mif)
{
System.Console.WriteLine(mf.Name);
}
System.Console.ReadLine();
System.Console.WriteLine("实例化HelloWorld,并调用SayHello方法");
Object obj = Activator.CreateInstance(ht);
string[] s = {"zhenlei"};
Object bojName = Activator.CreateInstance(ht,s);
BindingFlags flags = (BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.Static|BindingFlags.Instance|BindingFlags.DeclaredOnly);
MethodInfo msayhello = ht.GetMethod("SayHello");
msayhello.Invoke(obj,null);
msayhello.Invoke(objName,null);
System.Console.ReadLine();
}
}
}
而且我用反射好像只能获得类中public的方法、变量 不是很懂,望指导。