Example #1
0
        /// <summary>
        /// Define new file and fill it with generic functionality like header comments and pragmas.
        /// </summary>
        /// <param name="fileName">Name for new file.</param>
        private void DefineFile(string fileName)
        {
            var file = AST.File(fileName);

            _files.Add(fileName, (file, new()));

            // add standard `auto-generated` comment
            if (_dataModel.AutoGeneratedHeader != null)
            {
                // note that roslyn compiler disables NRT for files with auto-generated comment for backward compatibility and they should be re-enabled explicitly
                file.AddHeader(AST.Commentary("---------------------------------------------------------------------------------------------------", false));
                file.AddHeader(AST.Commentary("<auto-generated>", false));
                file.AddHeader(AST.Commentary(_dataModel.AutoGeneratedHeader, false));
                file.AddHeader(AST.Commentary("</auto-generated>", false));
                file.AddHeader(AST.Commentary("---------------------------------------------------------------------------------------------------", false));
            }

            // configure compiler options
            //
            // as we don't generate xml-doc comments except cases when we have descriptions for database objects
            // we should disable missing xml-doc warnings in generated code to avoid build errors/warnings in
            // projects with required xml-doc
            if (_dataModel.DisableXmlDocWarnings)
            {
                file.Add(AST.DisableWarnings(_languageProvider.MissingXmlCommentWarnCodes));
            }

            // enable NRT context if we have auto-generated comment which disables it
            if (_dataModel.NRTEnabled && _dataModel.AutoGeneratedHeader != null)
            {
                file.Add(AST.EnableNullableReferenceTypes());
            }

            // add extra line separator between generated header and other file content
            if (_dataModel.DisableXmlDocWarnings || (_dataModel.NRTEnabled && _dataModel.AutoGeneratedHeader != null))
            {
                file.Add(AST.NewLine);
            }
        }