Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Type t = Type.GetType("WebCore.Models.Page");
- object page = new t();
- public T GetInstance<T>(string type)
- {
- return (T)Activator.CreateInstance(Type.GetType(type));
- }
- T CreateType<T>() where T : new()
- {
- return new T();
- }
- using System;
- using System.Runtime.Remoting;
- class Program
- {
- static void Main()
- {
- ObjectHandle o = Activator.CreateInstance("mscorlib.dll", "System.Int32");
- Int32 i = (Int32)o.Unwrap();
- }
- }
- public static T GetInstance<T>(params object[] args)
- {
- return (T)Activator.CreateInstance(typeof(T), args);
- }
- public class Counter<T>
- {
- public T Value { get; set; }
- }
- string typeName = typeof(Counter<>).AssemblyQualifiedName;
- Type t = Type.GetType(typeName);
- Counter<int> counter =
- (Counter<int>)Activator.CreateInstance(
- t.MakeGenericType(typeof(int)));
- counter.Value++;
- Console.WriteLine(counter.Value);
- public static T Clone<T>(T original)
- {
- T newObject = (T)Activator.CreateInstance(original.GetType());
- foreach (var prop in original.GetType().GetProperties())
- {
- prop.SetValue(newObject, prop.GetValue(original));
- }
- return newObject;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement