コード例 #1
0
        private static string GenerateDataTableStringParser(DataTableProcessor dataTableProcessor, Data data)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder
            .AppendLine("        public override bool ParseDataRow(GameFrameworkSegment<string> dataRowSegment)")
            .AppendLine("        {")
            .AppendLine("            string[] text = DataTableExtension.SplitDataRow(dataRowSegment);")
            .AppendLine("            int index = 0;");

            for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
            {
                if (dataTableProcessor.IsCommentColumn(i))
                {
                    // 注释列
                    stringBuilder.AppendLine("            index++;");
                    continue;
                }

                if (i == dataTableProcessor.IdColumn)
                {
                    // 编号列
                    stringBuilder.AppendLine("            m_Id = int.Parse(text[index++]);");
                    continue;
                }

                string standardType = dataTableProcessor.GetStandardType(i);
                switch (standardType)
                {
                case "string":
                    stringBuilder.AppendFormat("            {0} = text[index++];", dataTableProcessor.GetName(i)).AppendLine();
                    break;

                default:
                    stringBuilder.AppendFormat("            {0} = {1}.Parse(text[index++]);", dataTableProcessor.GetName(i), standardType).AppendLine();
                    break;
                }
            }

            stringBuilder
            .AppendLine()
            .AppendLine("            return true;")
            .Append("        }");

            return(stringBuilder.ToString());
        }
コード例 #2
0
        private static string GenerateDataTableProperties(DataTableProcessor dataTableProcessor, Data data)
        {
            StringBuilder stringBuilder = new StringBuilder();
            bool          firstProperty = true;

            for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
            {
                if (dataTableProcessor.IsCommentColumn(i))
                {
                    // 注释列
                    continue;
                }

                if (i == dataTableProcessor.IdColumn)
                {
                    // 编号列
                    continue;
                }

                if (firstProperty)
                {
                    firstProperty = false;
                }
                else
                {
                    stringBuilder.AppendLine().AppendLine();
                }

                stringBuilder
                .AppendLine("        /// <summary>")
                .AppendFormat("        /// 获取{0}。", dataTableProcessor.GetComment(i)).AppendLine()
                .AppendLine("        /// </summary>")
                .AppendFormat("        public {0} {1}", dataTableProcessor.GetStandardType(i), dataTableProcessor.GetName(i)).AppendLine()
                .AppendLine("        {")
                .AppendLine("            get;")
                .AppendLine("            private set;")
                .Append("        }");
            }

            return(stringBuilder.ToString());
        }
コード例 #3
0
        private static string GenerateDataTablePropertyArray(DataTableProcessor dataTableProcessor, Data data)
        {
            Dictionary <string, string> propertyType = new Dictionary <string, string>();
            Dictionary <string, List <KeyValuePair <int, string> > > propertyArray = new Dictionary <string, List <KeyValuePair <int, string> > >();

            for (int i = 0; i < dataTableProcessor.RawColumnCount; i++)
            {
                if (dataTableProcessor.IsCommentColumn(i))
                {
                    // 注释列
                    continue;
                }

                if (i == dataTableProcessor.IdColumn)
                {
                    // 编号列
                    continue;
                }

                string name = dataTableProcessor.GetName(i);
                if (!EndWithNumberRegex.IsMatch(name))
                {
                    continue;
                }

                string arrayName = EndWithNumberRegex.Replace(name, string.Empty);
                int    id        = int.Parse(EndWithNumberRegex.Match(name).Value);

                List <KeyValuePair <int, string> > property = null;
                if (!propertyArray.TryGetValue(arrayName, out property))
                {
                    propertyType.Add(arrayName, dataTableProcessor.GetStandardType(i));
                    property = new List <KeyValuePair <int, string> >();
                    propertyArray.Add(arrayName, property);
                }

                property.Add(new KeyValuePair <int, string>(id, name));
            }

            StringBuilder stringBuilder = new StringBuilder();

            foreach (KeyValuePair <string, List <KeyValuePair <int, string> > > i in propertyArray)
            {
                stringBuilder
                .AppendFormat("        private KeyValuePair<int, {0}>[] m_{1} = null;", propertyType[i.Key], i.Key).AppendLine()
                .AppendFormat("        public int Get{0}(int id)", i.Key).AppendLine()
                .AppendLine("        {")
                .AppendFormat("            foreach (KeyValuePair<int, {0}> i in m_{1})", propertyType[i.Key], i.Key).AppendLine()
                .AppendLine("            {")
                .AppendLine("                if (i.Key == id)")
                .AppendLine("                {")
                .AppendFormat("                    return i.Value;", propertyType[i.Key], i.Key).AppendLine()
                .AppendLine("                }")
                .AppendLine("            }")
                .AppendLine()
                .AppendFormat("            throw new GameFrameworkException(Utility.Text.Format(\"Invalid id '{{0}}' for {0}.\", id.ToString()));", i.Key).AppendLine()
                .AppendLine("        }");
            }

            return(stringBuilder.ToString());
        }