/// <summary> /// 构建读取帮助者 /// </summary> /// <param name="byTmplType"></param> /// <returns></returns> public static IReadHelper Make(System.Type byTmplType) { if (byTmplType == null) { // 如果参数对象为空, // 则直接退出! return(null); } // 获取读取器 IReadHelper helperObj = GetHelperObj(byTmplType); if (helperObj == null) { // 如果读取器为空, // 则需要构建! lock (byTmplType) { // 注意: 在这里进行二次验证 helperObj = GetHelperObj(byTmplType); if (helperObj == null) { // 构建帮助器类定义 System.Type helperType = BuildHelperType(byTmplType); // 创建对象实例 helperObj = (IReadHelper)Activator.CreateInstance(helperType); // 添加到帮助器字典 PutHelperObj(byTmplType, helperObj); } } } return(helperObj); }
/// <summary> /// 保存帮助器到字典 /// </summary> /// <param name="byTmplType"></param> /// <param name="helperObj"></param> private static void PutHelperObj(System.Type byTmplType, IReadHelper helperObj) { // 断言参数不为空 Assert.NotNull(byTmplType, "byTmplType"); Assert.NotNull(helperObj, "helperObj"); // 保存帮助器到字典 _helperObjDict[byTmplType] = helperObj; }
// @Override public override void ReadFrom(BinaryReader br) { if (br == null) { // 如果参数对象为空, // 则直接退出! return; } // 获取帮助器对象 IReadHelper helperObj = ReadHelperMaker.Make(this.GetType()); if (helperObj != null) { // 如果帮助器不为空, // 则读取消息对象! helperObj.ReadMsgObjFrom(this, br); } }
// @Override protected override void ReadImpl(XlsxRowReadStream fromStream) { if (fromStream == null) { // 如果参数对象为空, // 则直接退出! return; } // 获取帮助器对象 IReadHelper helperObj = ReadHelperMaker.Make(this.GetType()); if (helperObj != null) { // 如果帮助器不为空, // 则读取消息对象! helperObj.ReadTmplObjFrom(this, fromStream); } }