Click here to Skip to main content
15,896,118 members
Articles / Programming Languages / C#

Reflection

Rate me:
Please Sign up or sign in to vote.
4.56/5 (61 votes)
17 Mar 20056 min read 206.5K   2K   159  
An article about Reflection in .NET, using C#.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace ReflectionCSharp
{
	/// <summary>
	/// Summary description for InvokeMethod.
	/// </summary>
	public class InvokeMethod : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button OK;
		private System.Windows.Forms.Label label1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public InvokeMethod()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.OK = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(40, 96);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(456, 20);
			this.textBox1.TabIndex = 0;
			this.textBox1.Text = "";
			// 
			// OK
			// 
			this.OK.Location = new System.Drawing.Point(208, 128);
			this.OK.Name = "OK";
			this.OK.Size = new System.Drawing.Size(48, 24);
			this.OK.TabIndex = 1;
			this.OK.Text = "OK";
			this.OK.Click += new System.EventHandler(this.OK_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(72, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(408, 64);
			this.label1.TabIndex = 2;
			// 
			// InvokeMethod
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(522, 168);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.OK);
			this.Controls.Add(this.textBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.Name = "InvokeMethod";
			this.Text = "InvokeMethod";
			this.Load += new System.EventHandler(this.InvokeMethod_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void InvokeMethod_Load(object sender, System.EventArgs e)
		{
			
		}
		public string setLabelText
		{
			set
			{
				label1.Text = value;
				label1.Text = label1.Text + " Enter the arguments separated by commas.";
			}
		}
		public  object[] getArgs()
		{
			char[] separator = {','};
			object[] args = textBox1.Text .Split (separator);
			if (args.Length == 0)
				return null;
			return args;
		}

		private void OK_Click(object sender, System.EventArgs e)
		{
			this.Close ();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions