RemotingHelper
1 public class RemotingHelper 2 { 3 private static bool _isInit; 4 private static IDictionary _wellKnownTypes; 5 public static object GetObject(Type type) 6 { 7 if (!_isInit) InitTypeCache(); 8 WellKnownClientTypeEntry item = (WellKnownClientTypeEntry)_wellKnownTypes[type]; 9 10 if (item == null) 11 { 12 throw new RemotingException("Type not found !"); 13 } 14 //为指定类型和 URL 所指示的已知对象创建一个代理。 15 return Activator.GetObject(item.ObjectType, item.ObjectUrl); 16 } 17 public static void InitTypeCache() 18 { 19 _isInit = true; 20 _wellKnownTypes = new Hashtable(); 21 foreach (WellKnownClientTypeEntry item in RemotingConfiguration.GetRegisteredWellKnownClientTypes()) 22 { 23 if (item.ObjectType == null) 24 { 25 throw new RemotingException("A configured type could not be found. Please check spelling"); 26 } 27 _wellKnownTypes.Add(item.ObjectType, item); 28 } 29 30 }
1 Type t = Assembly.LoadFrom(sDllName).GetType(sObjName); 2 //使用指定类型的默认构造函数来创建该类型的实例 3 Activator.CreateInstance(t);