示例#1
0
 /// <summary>
 ///     协议索引器,这是一个懒加载协议,当字典中不存在协议时自动加载协议,否则调用已经加载的协议
 /// </summary>
 /// <param name="type">协议的类的GetType</param>
 /// <returns>协议的实例</returns>
 public ProtocalUnit this[Type type]
 {
     get
     {
         var protocalName = type.FullName;
         if (Protocals.ContainsKey(protocalName))
         {
             return(Protocals[protocalName]);
         }
         //自动寻找存在的协议并将其加载
         var protocalUnit =
             Assembly.Load(type.Assembly.FullName).CreateInstance(protocalName) as ProtocalUnit;
         if (protocalUnit == null)
         {
             throw new InvalidCastException("没有相应的协议内容");
         }
         Register(protocalUnit);
         return(Protocals[protocalName]);
     }
 }
示例#2
0
 /// <summary>
 ///     协议索引器,这是一个懒加载协议,当字典中不存在协议时自动加载协议,否则调用已经加载的协议
 /// </summary>
 /// <param name="type">协议的类的GetType</param>
 /// <returns>协议的实例</returns>
 public ProtocalUnit this[Type type]
 {
     get
     {
         var protocalName = type.FullName;
         if (Protocals.ContainsKey(protocalName))
         {
             return(Protocals[protocalName]);
         }
         //自动寻找存在的协议并将其加载
         var protocalUnit =
             Activator.CreateInstance(type.GetTypeInfo().Assembly.GetType(protocalName)) as ProtocalUnit;
         if (protocalUnit == null)
         {
             throw new InvalidCastException("没有相应的协议内容");
         }
         protocalUnit.Endian = Endian;
         Register(protocalUnit);
         return(Protocals[protocalName]);
     }
 }