示例#1
0
        public object GetValue(int index, ICell valueCell)
        {
            if (valueCell == null)
            {
                return(null);
            }

            var type = types.Cells[index].StringCellValue;

            switch (type.ToLower())
            {
            case "int":
                return((int)valueCell.NumericCellValue);

            case "long":
                return((long)valueCell.NumericCellValue);

            case "float":
                return((float)valueCell.NumericCellValue);

            case "double":
                return(valueCell.NumericCellValue);

            case "bool":
                return(valueCell.BooleanCellValue);

            case "string":
                return(valueCell.ToString());

            case "datetime":
                return(valueCell.DateCellValue);

            case "int[]":
                return(GetArrayValue(valueCell, int.Parse));

            case "long[]":
                return(GetArrayValue(valueCell, long.Parse));

            case "float[]":
                return(GetArrayValue(valueCell, float.Parse));

            case "double[]":
                return(GetArrayValue(valueCell, double.Parse));

            case "bool[]":
                return(GetArrayValue(valueCell, bool.Parse));

            case "string[]":
                return(GetArrayValue(valueCell, s => s));

            case "datetime[]":
                return(GetArrayValue(valueCell, DateTime.Parse));

            case "enum":
                return(GetEnumValue(valueCell.ToString().ToTopUpper(), columns.Cells[index]));

            default:
                return(GetKeyTypeValue(valueCell.ToString(), ConvertibleTypeUtility.GetString(type)));
            }
        }
示例#2
0
     string MakeKvo(string key)
     {
         return(@"    [Serializable]
 public struct $Key$
 {
     public string Value;
 }"
                .Replace("$Key$", ConvertibleTypeUtility.GetString(key)));
     }
示例#3
0
        public string GenerateCode(IEnumerable <string> types)
        {
            var keys = types.Distinct().Where(t => !ConvertibleTypeUtility.IsDefined(t));

            var kvos = string
                       .Join(Environment.NewLine + Environment.NewLine, keys.Select(MakeKvo))
                       .TrimEnd(Environment.NewLine);

            return(masterKeyValueObjectsCodeTemplate
                   .Replace("$Namespace$", @namespace)
                   .Replace("$KeyValueObjects$", kvos));
        }
示例#4
0
        public string GenerateCode(string masterName, IRow columns, IRow types)
        {
            var fields = new StringBuilder();

            for (var i = 0; i < columns.Count(); i++)
            {
                var column = columns.GetCell(i).StringCellValue.ToTopUpper();
                var type   = types.GetCell(i).StringCellValue.ToLower();
                fields.Append($"        {MakeField(column, type)}{Environment.NewLine}");
            }

            var key = ConvertibleTypeUtility.GetString(types.GetCell(0).StringCellValue);

            return(scriptableObjectCodeTemplate
                   .Replace("$Namespace$", @namespace)
                   .Replace("$Master$", masterName)
                   .Replace("$Key$", key)
                   .Replace("$Columns$", fields.ToString().TrimEnd(Environment.NewLine))
                   .Replace("$ResourcePath$", GetPathUnderResources()));
        }
示例#5
0
 string MakeField(string column, string type)
 {
     return(type == "enum" ?
            $"public {column} {column};" :
            $"public {ConvertibleTypeUtility.GetString(type)} {column};");
 }