コード例 #1
0
        /// <summary>
        /// 代码分片
        /// </summary>
        /// <param name="value"></param>
        /// <param name="row"></param>
        /// <param name="col"></param>
        /// <param name="isSplit"></param>
        /// <returns>下一个节点</returns>
        internal CombinationTemplateLink Split(string value, int row, int col, ref bool isSplit)
        {
            CombinationTemplateLink next = this.next;

            if (value.Length != 0 && Code.Length >= value.Length)
            {
                string[] codeArray = Code.Split(new string[] { value }, StringSplitOptions.None);
                if (codeArray.Length > 1)
                {
                    CombinationTemplateLink link = this;
                    int index = 0;
                    foreach (string code in codeArray)
                    {
                        if (index == 0)
                        {
                            this.Code = code;
                        }
                        else
                        {
                            link.next = new CombinationTemplateLink(row, col);
                            link      = link.next;
                            link.next = new CombinationTemplateLink(code);
                            link      = link.next;
                        }
                        ++index;
                    }
                    if (!object.ReferenceEquals(this, next))
                    {
                        link.next = next;
                    }
                    isSplit = true;
                }
            }
            return(object.ReferenceEquals(this, next) ? null : next);
        }
コード例 #2
0
 /// <summary>
 /// 替换节点
 /// </summary>
 /// <param name="row"></param>
 /// <param name="col"></param>
 private CombinationTemplateLink(int row, int col)
 {
     Code = string.Empty;
     Row  = row;
     Col  = col;
     next = this;
 }
コード例 #3
0
 /// <summary>
 /// 自定义简单组合模板链
 /// </summary>
 /// <param name="code">模板代码片段</param>
 internal CombinationTemplateLink(string code)
 {
     this.Code = code;
     Row       = Col = -1;
     next      = this;
 }
コード例 #4
0
        /// <summary>
        /// 生成代码
        /// </summary>
        /// <param name="fileName">模板文件名</param>
        /// <returns>代码</returns>
        private static LeftArray <string> getCode(string fileName)
        {
            string code = File.ReadAllText(fileName, System.Text.Encoding.UTF8);
            int    startIndex = code.IndexOf("/*", StringComparison.Ordinal), endIndex = code.IndexOf(@"*/

", startIndex + 2, StringComparison.Ordinal);

            if (endIndex > 0 && startIndex > 0)
            {
                LeftArray <string[][]> headerArray = new LeftArray <string[][]>(0);
                foreach (SubString line in new SubString(startIndex += 2, endIndex - startIndex, code).Trim().Split('\n'))
                {
                    SubString headerLine = line.Trim();
                    if (headerLine.Length != 0)
                    {
                        headerArray.Add(headerLine.Split(';').GetArray(p => p.Split(',').GetArray(v => (string)v)));
                    }
                }
                if (headerArray.Length != 0)
                {
                    CombinationTemplateLink header = new CombinationTemplateLink(code = code.Substring(endIndex + 4));
                    int row = 0;
                    foreach (string[][] line in headerArray)
                    {
                        int col = 0;
                        foreach (string value in line[0])
                        {
                            bool isSplit = false;
                            CombinationTemplateLink link = header;
                            do
                            {
                                link = link.Split(value, row, col, ref isSplit);
                            }while (link != null);
                            if (!isSplit)
                            {
                                Messages.Error("自定义简单组合模板文件内容没有找到匹配替换标记 " + value + " : " + fileName);
                                return(new LeftArray <string>(0));
                            }
                            ++col;
                        }
                        ++row;
                    }
                    LeftArray <CombinationTemplateLink> linkArray = new LeftArray <CombinationTemplateLink>(0);
                    LeftArray <string> codeArray = new LeftArray <string>(0);
                    do
                    {
                        if (header.Row >= 0)
                        {
                            linkArray.Add(header);
                            header.Index = codeArray.Length;
                            codeArray.Add(string.Empty);
                        }
                        else
                        {
                            codeArray.Add(header.Code);
                        }
                    }while ((header = header.Next) != null);
                    CombinationTemplateHeaderEnumerable headerEnumerable = new CombinationTemplateHeaderEnumerable(ref headerArray, codeArray.ToArray(), linkArray.ToArray());
                    codeArray.Length = 0;
                    foreach (string enumerableCode in headerEnumerable.GetCode())
                    {
                        codeArray.Add(enumerableCode);
                    }
                    return(codeArray);
                }
                else
                {
                    Messages.Error("自定义简单组合模板文件缺少头部信息解析失败 : " + fileName);
                }
            }
            else
            {
                Messages.Error("自定义简单组合模板文件缺少头部注释信息 : " + fileName);
            }
            return(new LeftArray <string>(0));
        }