G
Guest
I have an application that is being passed objects which could either be an instance or a Type in the case of a Static Class
When you do the GetType on the object that was originally a Static class it gives you a type of "System.RuntimeType" as opposed to the orignal Static Class Typ
How do you get access to what type the the Orginal Static Class type was from the RuntimeType??
//Eg Routine......
Object[] objects = new Object[3]
Class1 class1 = new Class1("Class1")
objects[0] = class1
objects[1] = typeof(StaticClass)
objects[2] = typeof(StaticClass).FullName
//objects[1] = (Object)StaticClass
foreach (object o in objects
tr
Type type = o.GetType()
this.richTextBox1.Text += type.FullName+NL
if (type.FullName == "System.RuntimeType"
//??????? Here is what I need....How to Get the Orignal Static Class back????? from a
//System.RuntimeType???
else if (type.FullName == "System.String"
Type originalType = Type.GetType((string) o)
this.richTextBox1.Text += originalType.FullName+NL
catch (Exception ex
this.richTextBox1.Text += ex.Message+NL
******** Complete sample code Listin
using System
using System.Drawing
using System.Collections
using System.ComponentModel
using System.Windows.Forms
using System.Data
namespace MJBStaticTypesInOb
public class Form1 : System.Windows.Forms.For
private System.Windows.Forms.Button button1
private System.Windows.Forms.RichTextBox richTextBox1
private System.ComponentModel.Container components = null
public Form1(
InitializeComponent()
/// <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 cod
/// <summary
/// Required method for Designer support - do not modif
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(
this.button1 = new System.Windows.Forms.Button()
this.richTextBox1 = new System.Windows.Forms.RichTextBox()
this.SuspendLayout()
//
// button
//
this.button1.Location = new System.Drawing.Point(32, 96)
this.button1.Name = "button1"
this.button1.TabIndex = 0
this.button1.Text = "button1"
this.button1.Click += new System.EventHandler(this.button1_Click)
//
// richTextBox
//
this.richTextBox1.Location = new System.Drawing.Point(24, 152)
this.richTextBox1.Name = "richTextBox1"
this.richTextBox1.Size = new System.Drawing.Size(208, 96)
this.richTextBox1.TabIndex = 1
this.richTextBox1.Text = "richTextBox1"
//
// Form
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13)
this.ClientSize = new System.Drawing.Size(292, 266)
this.Controls.Add(this.richTextBox1)
this.Controls.Add(this.button1)
this.Name = "Form1"
this.Text = "Form1"
this.ResumeLayout(false)
#endregio
/// <summary
/// The main entry point for the application
/// </summary
[STAThread
static void Main()
Application.Run(new Form1())
private void button1_Click(object sender, System.EventArgs e
string NL = Environment.NewLine
this.richTextBox1.Text = string.Empty
Object[] objects = new Object[3]
Class1 class1 = new Class1("Class1")
objects[0] = class1
objects[1] = typeof(StaticClass)
objects[2] = typeof(StaticClass).FullName
//objects[1] = (Object)StaticClass
foreach (object o in objects
tr
Type type = o.GetType()
this.richTextBox1.Text += type.FullName+NL
if (type.FullName == "System.RuntimeType"
//How to Get the Orignal Static Class back????? from a
//System.RuntimeType???
else if (type.FullName == "System.String"
Type originalType = Type.GetType((string) o)
this.richTextBox1.Text += originalType.FullName+NL
catch (Exception ex
this.richTextBox1.Text += ex.Message+NL
public class StaticClas
public static string Name = "StaticClass"
static StaticClass(){
public class Class
public string Name = "InstanceClass"
public Class1(string name)
{
Name = name;
}
}
}
When you do the GetType on the object that was originally a Static class it gives you a type of "System.RuntimeType" as opposed to the orignal Static Class Typ
How do you get access to what type the the Orginal Static Class type was from the RuntimeType??
//Eg Routine......
Object[] objects = new Object[3]
Class1 class1 = new Class1("Class1")
objects[0] = class1
objects[1] = typeof(StaticClass)
objects[2] = typeof(StaticClass).FullName
//objects[1] = (Object)StaticClass
foreach (object o in objects
tr
Type type = o.GetType()
this.richTextBox1.Text += type.FullName+NL
if (type.FullName == "System.RuntimeType"
//??????? Here is what I need....How to Get the Orignal Static Class back????? from a
//System.RuntimeType???
else if (type.FullName == "System.String"
Type originalType = Type.GetType((string) o)
this.richTextBox1.Text += originalType.FullName+NL
catch (Exception ex
this.richTextBox1.Text += ex.Message+NL
******** Complete sample code Listin
using System
using System.Drawing
using System.Collections
using System.ComponentModel
using System.Windows.Forms
using System.Data
namespace MJBStaticTypesInOb
public class Form1 : System.Windows.Forms.For
private System.Windows.Forms.Button button1
private System.Windows.Forms.RichTextBox richTextBox1
private System.ComponentModel.Container components = null
public Form1(
InitializeComponent()
/// <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 cod
/// <summary
/// Required method for Designer support - do not modif
/// the contents of this method with the code editor
/// </summary
private void InitializeComponent(
this.button1 = new System.Windows.Forms.Button()
this.richTextBox1 = new System.Windows.Forms.RichTextBox()
this.SuspendLayout()
//
// button
//
this.button1.Location = new System.Drawing.Point(32, 96)
this.button1.Name = "button1"
this.button1.TabIndex = 0
this.button1.Text = "button1"
this.button1.Click += new System.EventHandler(this.button1_Click)
//
// richTextBox
//
this.richTextBox1.Location = new System.Drawing.Point(24, 152)
this.richTextBox1.Name = "richTextBox1"
this.richTextBox1.Size = new System.Drawing.Size(208, 96)
this.richTextBox1.TabIndex = 1
this.richTextBox1.Text = "richTextBox1"
//
// Form
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13)
this.ClientSize = new System.Drawing.Size(292, 266)
this.Controls.Add(this.richTextBox1)
this.Controls.Add(this.button1)
this.Name = "Form1"
this.Text = "Form1"
this.ResumeLayout(false)
#endregio
/// <summary
/// The main entry point for the application
/// </summary
[STAThread
static void Main()
Application.Run(new Form1())
private void button1_Click(object sender, System.EventArgs e
string NL = Environment.NewLine
this.richTextBox1.Text = string.Empty
Object[] objects = new Object[3]
Class1 class1 = new Class1("Class1")
objects[0] = class1
objects[1] = typeof(StaticClass)
objects[2] = typeof(StaticClass).FullName
//objects[1] = (Object)StaticClass
foreach (object o in objects
tr
Type type = o.GetType()
this.richTextBox1.Text += type.FullName+NL
if (type.FullName == "System.RuntimeType"
//How to Get the Orignal Static Class back????? from a
//System.RuntimeType???
else if (type.FullName == "System.String"
Type originalType = Type.GetType((string) o)
this.richTextBox1.Text += originalType.FullName+NL
catch (Exception ex
this.richTextBox1.Text += ex.Message+NL
public class StaticClas
public static string Name = "StaticClass"
static StaticClass(){
public class Class
public string Name = "InstanceClass"
public Class1(string name)
{
Name = name;
}
}
}