RemotingHelper 构建远程对象
public class RemotingHelper { private static bool _isInit; private static IDictionary _wellKnownTypes; public static object GetObject(Type type) { if (!_isInit) InitTypeCache(); WellKnownClientTypeEntry item = (WellKnownClientTypeEntry)_wellKnownTypes[type]; if (item == null) { throw new RemotingException("Type not found !"); } //为指定类型和 URL 所指示的已知对象创建一个代理。 return Activator.GetObject(item.ObjectType, item.ObjectUrl); } public static void InitTypeCache() { _isInit = true; _wellKnownTypes = new Hashtable(); foreach (WellKnownClientTypeEntry item in RemotingConfiguration.GetRegisteredWellKnownClientTypes()) { if (item.ObjectType == null) { throw new RemotingException("A configured type could not be found. Please check spelling"); } _wellKnownTypes.Add(item.ObjectType, item); } } }
1 Type t = Assembly.LoadFrom(sDllName).GetType(sObjName); 2 // 使用指定类型的默认构造函数来创建该类型的实例 3 Activator.CreateInstance(t);