Esempio n. 1
0
        private string GetScriptOutPath(CsharpCreateInfo createInfo,
                                        string directory)
        {
            var finalPath = directory.EnsureDirectoryFormat() +
                            createInfo.ScriptName + ".cs";

            return(finalPath);
        }
Esempio n. 2
0
        /// <summary>
        /// 获取脚本内容
        /// </summary>
        /// <param name="csharpScriptAppender"></param>
        /// <param name="csharpCreateInfo"></param>
        /// <returns></returns>
        private string GetScriptContent(CsharpScriptAppender scriptAppender,
                                        CsharpCreateInfo csharpCreateInfo)
        {
            #region Local Method
            //尝试添加版权信息
            TryAppendCopyRight();

            if (requireAddIfPrecompile)
            {
                using (new IfPreCompileBlock(scriptAppender,
                                             new List <string> {
                    IfPrecompile
                }))
                {
                    scriptAppender.AppendLine();
                    scriptAppender.AppendCommentHeader(developerInfo.Name,
                                                       developerInfo.Email);

                    using (new IfPreCompileBlock(scriptAppender,
                                                 csharpCreateInfo.IfPreCompileInstructions))
                    {
                        using (new NameSpaceBlock(scriptAppender, globalNameSpace))
                        {
                            AppendScriptContent();
                        }
                    }
                }
            }
            else
            {
                scriptAppender.AppendCommentHeader(developerInfo.Name,
                                                   developerInfo.Email);
                using (new NameSpaceBlock(scriptAppender, globalNameSpace))
                {
                    AppendScriptContent();
                }
            }

            return(scriptAppender.ToString());

            void AppendScriptContent()
            {
                var clasaHeadString = string.Format("public {0} {1}",
                                                    GetStringKeyword(csharpCreateInfo.CsharpScriptType),
                                                    csharpCreateInfo.ScriptName);

                scriptAppender.AppendLine(clasaHeadString);
                scriptAppender.AppenLeftBracketAndToRight();
                scriptAppender.AppendLine();
                scriptAppender.AppendToLeftAndRightBracket();
            }

            string GetStringKeyword(CsharpScriptType csharpScriptType)
            {
                switch (csharpScriptType)
                {
                case CsharpScriptType.Class:
                    return("class");

                case CsharpScriptType.AbstractClass:
                    return("abstract class");

                case CsharpScriptType.Interface:
                    return("interface");

                case CsharpScriptType.Enum:
                    return("enum");

                case CsharpScriptType.Struct:
                    return("struct");

                default:
                    throw new ArgumentOutOfRangeException(
                              nameof(csharpScriptType), csharpScriptType, null);
                }
            }

            void TryAppendCopyRight()
            {
                if (!copyRightContent.IsValid())
                {
                    return;
                }
                //scriptAppender.AppendLine(copyRightContent);
                //scriptAppender.AppendLine();
                scriptAppender.AppendMultiComment(copyRightContent);
            }

            #endregion
        }