【特性】支持为容器类型自身及key,value类型单独指定属性(例如 map,(int&ref=test),(int&path=unity)&tag_of_map=xxx)

main
walon 2021-10-24 20:07:32 +08:00
parent 08720156e8
commit 06467344a5
4 changed files with 60 additions and 29 deletions

View File

@ -8,28 +8,9 @@ using Luban.Job.Common.Types;
using Luban.Job.Common.TypeVisitors; using Luban.Job.Common.TypeVisitors;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Luban.Job.Cfg.DataCreators namespace Luban.Job.Cfg.DataCreators
{ {
class InvalidExcelDataException : Exception
{
public InvalidExcelDataException()
{
}
public InvalidExcelDataException(string message) : base(message)
{
}
public InvalidExcelDataException(string message, Exception innerException) : base(message, innerException)
{
}
protected InvalidExcelDataException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
class ExcelStreamDataCreator : ITypeFuncVisitor<ExcelStream, DType> class ExcelStreamDataCreator : ITypeFuncVisitor<ExcelStream, DType>
{ {

View File

@ -0,0 +1,24 @@
using System;
using System.Runtime.Serialization;
namespace Luban.Job.Cfg.DataCreators
{
class InvalidExcelDataException : Exception
{
public InvalidExcelDataException()
{
}
public InvalidExcelDataException(string message) : base(message)
{
}
public InvalidExcelDataException(string message, Exception innerException) : base(message, innerException)
{
}
protected InvalidExcelDataException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}

View File

@ -73,29 +73,29 @@ namespace Luban.Job.Common.Defs
} }
} }
private readonly Dictionary<(DefTypeBase, bool), TType> cacheDefTTypes = new Dictionary<(DefTypeBase, bool), TType>(); private readonly Dictionary<(DefTypeBase, bool), TType> _cacheDefTTypes = new Dictionary<(DefTypeBase, bool), TType>();
protected TType GetOrCreateTEnum(DefEnum defType, bool nullable) protected TType GetOrCreateTEnum(DefEnum defType, bool nullable)
{ {
if (cacheDefTTypes.TryGetValue((defType, nullable), out var t)) if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t))
{ {
return t; return t;
} }
else else
{ {
return cacheDefTTypes[(defType, nullable)] = TEnum.Create(nullable, defType); return _cacheDefTTypes[(defType, nullable)] = TEnum.Create(nullable, defType);
} }
} }
protected TType GetOrCreateTBean(DefTypeBase defType, bool nullable) protected TType GetOrCreateTBean(DefTypeBase defType, bool nullable)
{ {
if (cacheDefTTypes.TryGetValue((defType, nullable), out var t)) if (_cacheDefTTypes.TryGetValue((defType, nullable), out var t))
{ {
return t; return t;
} }
else else
{ {
return cacheDefTTypes[(defType, nullable)] = TBean.Create(nullable, (DefBeanBase)defType); return _cacheDefTTypes[(defType, nullable)] = TBean.Create(nullable, (DefBeanBase)defType);
} }
} }
@ -137,6 +137,18 @@ namespace Luban.Job.Common.Defs
protected TType CreateNotContainerType(string module, string rawType) protected TType CreateNotContainerType(string module, string rawType)
{ {
bool nullable; bool nullable;
// 去掉 rawType 两侧的匹配的 ()
while (rawType.Length > 0 && rawType[0] == '(')
{
if (rawType[rawType.Length - 1] == ')')
{
rawType = rawType.Substring(1, rawType.Length - 2);
}
else
{
throw new Exception($"type:{rawType} brace not match");
}
}
var (type, tags) = DefUtil.ParseType(rawType); var (type, tags) = DefUtil.ParseType(rawType);
#if !LUBAN_LITE #if !LUBAN_LITE

View File

@ -44,11 +44,25 @@ namespace Luban.Job.Common.Utils
} }
else else
{ {
#if !LUBAN_LITE int braceDepth = 0;
return (s[..sepIndex], ParseAttrs(s[(sepIndex + 1)..])); for (int i = 0; i < s.Length; i++)
#else {
return (s.Substring(0, sepIndex), ParseAttrs(s.Substring(sepIndex + 1))); var c = s[i];
#endif if (c == '(')
{
++braceDepth;
}
else if (c == ')')
{
--braceDepth;
}
if (braceDepth == 0 && (c == '#' || c == '&' || c == '|'))
{
return (s.Substring(0, i), ParseAttrs(s.Substring(i + 1)));
}
}
return (s, new Dictionary<string, string>());
} }
} }