Exemplo n.º 1
0
        /// <summary>
        /// 构建写出帮助器
        /// </summary>
        /// <param name="byMsgType"></param>
        /// <returns></returns>
        public static IWriteHelper Make(System.Type byMsgType)
        {
            if (byMsgType == null)
            {
                // 如果参数对象为空,
                // 则直接退出!
                return(null);
            }

            // 获取写出器
            IWriteHelper helperObj = GetHelperObj(byMsgType);

            if (helperObj == null)
            {
                // 如果写出器为空,
                // 则需要构建!
                lock (byMsgType)
                {
                    // 注意: 在这里进行二次验证
                    helperObj = GetHelperObj(byMsgType);

                    if (helperObj == null)
                    {
                        // 构建帮助器类定义
                        System.Type helperType = BuildHelperType(byMsgType);
                        // 创建对象实例
                        helperObj = (IWriteHelper)Activator.CreateInstance(helperType);
                        // 添加到帮助器字典
                        PutHelperObj(byMsgType, helperObj);
                    }
                }
            }

            return(helperObj);
        }
Exemplo n.º 2
0
 /// <summary>
 /// 保存帮助器到字典
 /// </summary>
 /// <param name="byMsgType"></param>
 /// <param name="helperObj"></param>
 private static void PutHelperObj(System.Type byMsgType, IWriteHelper helperObj)
 {
     // 断言参数不为空
     Assert.NotNull(byMsgType, "byMsgType");
     Assert.NotNull(helperObj, "helperObj");
     // 保存帮助器到字典
     _helperObjDict[byMsgType] = helperObj;
 }
Exemplo n.º 3
0
        public ConsoleWriter(IWriteHelper consoleWriteHelper = null)
        {
            ConsoleWriteHelper = consoleWriteHelper ?? new ConsoleWriteHelper();
            var displayInformation = ReadInConfigFile();

            if (!displayInformation.IsConsole)
            {
                throw new NotImplementedException();
            }

            _writeToConsole = true;
        }
Exemplo n.º 4
0
        // @Override
        public override void WriteTo(BinaryWriter bw)
        {
            if (bw == null)
            {
                // 如果参数对象为空,
                // 则直接退出!
                return;
            }

            IWriteHelper helperObj = WriteHelperMaker.Make(this.GetType());

            if (helperObj != null)
            {
                // 如果帮助器不为空,
                // 则写出消息对象!
                helperObj.WriteMsgObjTo(this, bw);
            }
        }