Mega Code Archive

 
Categories / C# / Reflection
 

Create types of objects locally or remotely, or obtain references to existing remote objects

using System; using System.Reflection; using System.Text; public class SomeType {     public void DoSomething(int x)     {         Console.WriteLine(x);     } } public class Example {     static void Main()     {         Object o = Activator.CreateInstance(typeof(StringBuilder));         StringBuilder sb = (StringBuilder) o;         sb.Append("Hello, there.");         Console.WriteLine(sb);         System.Runtime.Remoting.ObjectHandle oh = Activator.CreateInstanceFrom(Assembly.GetEntryAssembly().CodeBase, typeof(SomeType).FullName);         SomeType st = (SomeType) oh.Unwrap();         st.DoSomething(5);     } }