解决方案 »
- android请求webervice问题 在线等....
- android拨号过程中应用层调用enableApnType是怎样与telephony层相连的?
- android应用调用add_service需要增加什么权限
- 事件挂接问题
- 你们希望实现的功能是什么?
- 安装apk时,解析包出现错误???
- 一个关于android动态加载数据的问题
- 移动卡 显示R的信号标志
- android数据库求助
- 请问程序报这样的错该怎么解决呀?
- 很急!!! java.lang.NoClassDefFoundError: com.android.volley.toolbox.Volley
- Activity 切换问题(或者说按Home键finish Activity)
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="vertical" > <Gallery android:id="@+id/gallery" android:layout_width="match_parent" android:layout_height="match_parent" android:spacing="10dp" /></RelativeLayout>
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;namespace GuiReflect
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtB_Name;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox txtB_Method;
private System.Windows.Forms.TextBox txtB_property;
private System.Windows.Forms.TextBox txtB_parent;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label labNameSpace;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.txtB_Name = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.labNameSpace = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txtB_parent = new System.Windows.Forms.TextBox();
this.txtB_property = new System.Windows.Forms.TextBox();
this.txtB_Method = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// txtB_Name
//
this.txtB_Name.Location = new System.Drawing.Point(144, 30);
this.txtB_Name.Name = "txtB_Name";
this.txtB_Name.Size = new System.Drawing.Size(272, 21);
this.txtB_Name.TabIndex = 0;
this.txtB_Name.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(40, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(56, 16);
this.label1.TabIndex = 1;
this.label1.Text = "c#类名";
this.label1.Click += new System.EventHandler(this.label1_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.labNameSpace);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.txtB_parent);
this.groupBox1.Controls.Add(this.txtB_property);
this.groupBox1.Controls.Add(this.txtB_Method);
this.groupBox1.Location = new System.Drawing.Point(16, 96);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(624, 360);
this.groupBox1.TabIndex = 2;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "结果显示";
//
// labNameSpace
//
this.labNameSpace.Location = new System.Drawing.Point(72, 24);
this.labNameSpace.Name = "labNameSpace";
this.labNameSpace.Size = new System.Drawing.Size(272, 23);
this.labNameSpace.TabIndex = 7;
this.labNameSpace.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 24);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(56, 23);
this.label5.TabIndex = 6;
this.label5.Text = "命名空间";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label4
//
this.label4.Location = new System.Drawing.Point(462, 64);
this.label4.Name = "label4";
this.label4.TabIndex = 5;
this.label4.Text = "父类列表";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label3
//
this.label3.Location = new System.Drawing.Point(264, 64);
this.label3.Name = "label3";
this.label3.TabIndex = 4;
this.label3.Text = "属性列表";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
this.label2.Location = new System.Drawing.Point(24, 64);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(176, 23);
this.label2.TabIndex = 3;
this.label2.Text = "方法列表";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// txtB_parent
//
this.txtB_parent.Location = new System.Drawing.Point(416, 96);
this.txtB_parent.Multiline = true;
this.txtB_parent.Name = "txtB_parent";
this.txtB_parent.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txtB_parent.Size = new System.Drawing.Size(192, 240);
this.txtB_parent.TabIndex = 2;
this.txtB_parent.Text = "";
//
// txtB_property
//
this.txtB_property.Location = new System.Drawing.Point(226, 96);
this.txtB_property.Multiline = true;
this.txtB_property.Name = "txtB_property";
this.txtB_property.ScrollBars = System.Windows.Forms.ScrollBars.Both;
this.txtB_property.Size = new System.Drawing.Size(176, 240);
this.txtB_property.TabIndex = 1;
this.txtB_property.Text = "";
//
// txtB_Method
//
this.txtB_Method.Location = new System.Drawing.Point(24, 96);
this.txtB_Method.Multiline = true;
this.txtB_Method.Name = "txtB_Method";
this.txtB_Method.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtB_Method.Size = new System.Drawing.Size(176, 240);
this.txtB_Method.TabIndex = 0;
this.txtB_Method.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(520, 29);
this.button1.Name = "button1";
this.button1.TabIndex = 3;
this.button1.Text = "获得列表";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(656, 469);
this.Controls.Add(this.button1);
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtB_Name);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "代码反射机制的应用";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void label1_Click(object sender, System.EventArgs e)
{
} private void button1_Click(object sender, System.EventArgs e)
{
labNameSpace.Text="";
txtB_Method.Text="";
txtB_property.Text="";
txtB_parent.Text="";
if(txtB_Name.Text=="")
txtB_Method.Text="类名不能为空";
else
{
string test="System."+txtB_Name.Text.ToString().Trim();
try
{
Type carType=Type.GetType(test);
labNameSpace.Text=carType.Namespace.ToString();
//得到类的方法代码
MethodInfo [] methods=carType.GetMethods();
int NumMethod=0;
foreach(MethodInfo method in methods)
{
NumMethod++;
txtB_Method.Text+=NumMethod+"->"+method.Name.ToString()+" ";
}
//得到类的属性的代码
PropertyInfo [] properties=carType.GetProperties();
int NumPropertie=0;
foreach(PropertyInfo propertie in properties)
{
NumPropertie++;
txtB_property.Text+=NumPropertie+"->"+propertie.Name.ToString()+" ";
}
//得到类的层次机构的代码
int NumParent=0;
Type parent=carType.BaseType;
while(parent!=null)
{
NumParent++;
txtB_parent.Text+=NumParent+"->"+parent.Name.ToString()+" ";
parent=parent.BaseType;
}
}
catch(TypeLoadException e1)
{
txtB_Method.Text=e1.Message;
}
catch(Exception e2)
{
txtB_Method.Text=e2.Message;
}
}
}
}
}
Type.GetType(Resource.Drawable) 是不是就获得了 Drawable 的Type对象? 但是好像还是报了 错