RemotingHelper.cs
上传用户:jasonxu888
上传日期:2007-03-28
资源大小:4316k
文件大小:1k
源码类别:

.net编程

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.Runtime.Remoting;
  4. namespace RemotingTools
  5. {
  6. public class RemotingHelper {
  7. private static bool _isInit;
  8. private static IDictionary _wellKnownTypes;
  9. public static Object GetObject(Type type) {
  10. if (! _isInit) InitTypeCache();
  11. WellKnownClientTypeEntry entr = (WellKnownClientTypeEntry) _wellKnownTypes[type];
  12. if (entr == null) {
  13. throw new RemotingException("Type not found!");
  14. }
  15. return Activator.GetObject(entr.ObjectType,entr.ObjectUrl);
  16. }
  17. public static void InitTypeCache() {
  18. _wellKnownTypes= new Hashtable();
  19. foreach (WellKnownClientTypeEntry entr in 
  20. RemotingConfiguration.GetRegisteredWellKnownClientTypes()) {
  21. _wellKnownTypes.Add (entr.ObjectType,entr);
  22. }
  23. }
  24. }
  25. }