Exemplo n.º 1
0
        /// <summary>
        /// 打开文档
        /// </summary>
        /// <typeparam name="T">文档类型</typeparam>
        /// <returns>文档</returns>
        public T OpenDocument <T>() where T : DocumentBase
        {
            DocumentBase document = this.Documents.SingleOrDefault(x => x.GetType().FullName == typeof(T).FullName);

            if (document == null)
            {
                document = ResolveMediator.Resolve <T>();
                this.Documents.Add(document);
            }

            document.Open();

            return((T)document);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 打开文档
        /// </summary>
        /// <param name="type">文档类型</param>
        /// <returns>文档</returns>
        public DocumentBase OpenDocument(Type type)
        {
            //验证
            if (!type.IsSubclassOf(typeof(DocumentBase)))
            {
                throw new InvalidCastException("给定类型不是文档!");
            }

            DocumentBase document = this.Documents.SingleOrDefault(x => x.GetType().FullName == type.FullName);

            if (document == null)
            {
                document = (DocumentBase)ResolveMediator.Resolve(type);
                this.Documents.Add(document);
            }

            document.Open();

            return(document);
        }