zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    python note 30 断点续传
    python note 29 线程创建
    python note 28 socketserver
    python note 27 粘包
    python note 26 socket
    python note 25 约束
    Sed 用法
    python note 24 反射
    python note 23 组合
    python note 22 面向对象成员
  • 原文地址:https://www.cnblogs.com/shenshiting/p/7776590.html
Copyright © 2011-2022 走看看