Exemple #1
0
        /// <summary>
        /// 填充类信息
        /// </summary>
        private void FillClassInfo()
        {
            ClrType ctype = _classType;

            _className = ctype.Name;

            _baseType = GetBaseClass(ctype, out _baseTypeName);

            _fileName = GetFileName(ctype, out _cp);
            EnvDTE.ProjectItem classItem = GetProjectItemByFileName(DesignerInfo, _fileName);
            //foreach (CodeElementPosition cp in ctype.SourceCodePositions)
            //{
            //    if (cp.FileName.IndexOf(".extend.cs") <0)
            //    {
            //        _fileName = cp.FileName;

            //        _cp = cp;
            //        break;
            //    }
            //}
            _namespace    = ctype.OwnerNamespace.Name;
            _summary      = ctype.DocSummary;
            _tableName    = EntityFieldBase.ToCamelName(_className);
            _lstSource    = CodeFileHelper.ReadFile(FileName);
            _fileEncoding = CodeFileHelper.GetFileEncoding(_fileName);
            if (ctype.Generic)
            {
                InitGeneric(ctype, _dicGenericInfo);
            }
        }
Exemple #2
0
        /// <summary>
        /// 生成生成器
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        private static CodeGenInfo CreateGenerationer(string path, EntityInfo entityInfo)
        {
            FileInfo file         = new FileInfo(path);
            string   workspace    = file.DirectoryName;
            Encoding encoding     = CodeFileHelper.GetFileEncoding(path);
            string   content      = File.ReadAllText(path, encoding);
            string   backCodePath = path + "c";
            string   backCode     = "";

            if (File.Exists(backCodePath))
            {
                encoding = CodeFileHelper.GetFileEncoding(backCodePath);
                backCode = File.ReadAllText(backCodePath, encoding);
            }
            //if (backCode == null)
            //{
            //    backCode = "";
            //}
            ModelCompiler compiler      = new ModelCompiler(content, backCode, entityInfo);
            string        className     = "ModelCompilerClass" + _classCount;
            StringBuilder sbError       = new StringBuilder();
            StringBuilder lastCodeCache = new StringBuilder();
            CodeGenInfo   info          = compiler.GetCompileType(className, lastCodeCache, sbError);

            if (sbError.Length > 0)
            {
                CompileException ex = new CompileException("模版编译错误:\n" + sbError);
                ex.Code = lastCodeCache.ToString();
                throw ex;
            }


            _classCount++;
            return(info);
        }