Example #1
0
        /// <summary>
        /// 数组
        /// </summary>
        /// <param name="attributes"></param>
        /// <param name="type"></param>
        /// <param name="typeDefined"></param>
        /// <param name="cellData"></param>
        /// <param name="errors"></param>
        /// <returns></returns>
        private object GetArray(AttributeTable attributes, string type, object typeDefined, ICell cellData, List <string> errors)
        {
            string cellText = null;

            if (cellData == null || cellData.CellType == CellType.Blank)
            {
                cellText = "";
            }
            else if (cellData.CellType == CellType.String)
            {
                cellText = cellData.StringCellValue.Trim();
            }
            else if (cellData.CellType == CellType.Numeric)
            {
                cellText = cellData.NumericCellValue.ToString();
            }
            else if (cellData.CellType == CellType.Boolean)
            {
                cellText = cellData.BooleanCellValue.ToString();
            }

            if (cellText == null)
            {
                cellText = "";
                errors.Add(string.Format("内容无法转换成有效的{0}数组。", type));
            }

            cellText = cellText.Trim();

            var separator  = ",";
            var arrayValue = attributes.GetAttribute <ArrayLiteral>();

            if (arrayValue != null)
            {
                separator = arrayValue.separator;
                if (cellText.StartsWith(arrayValue.beginning))
                {
                    cellText = cellText.Substring(arrayValue.beginning.Length);
                }
                if (cellText.EndsWith(arrayValue.ending))
                {
                    cellText = cellText.Substring(0, cellText.Length - arrayValue.ending.Length);
                }
            }

            var texts = string.IsNullOrEmpty(cellText) ? new string[] { } : cellText.Split(new string[] { separator }, StringSplitOptions.None);

            if (BaseUtil.IsBaseType(type))
            {
                return(BaseUtil.GetScalarArray(type, texts, errors));
            }
            else if (typeDefined is Model.Enum)
            {
                return(BaseUtil.GetEnumArray(typeDefined as Model.Enum, texts, errors));
            }
            else if (typeDefined is Model.Struct)
            {
                return(BaseUtil.GetStructArray(attributes, typeDefined as Model.Struct, texts, errors));
            }

            return(null);
        }