public void InitCustomType(LBType customType) { IsCustomType = true; IsClass = customType.IsClass; IsStruct = customType.IsStruct; FieldTypes = customType.FieldTypes; }
/// <summary> 检查字段的有效性 | Check the validity of all custom types </summary> private static void CheckType(LBType type) { if (type.IsArray) { // 数组 | Array CheckType(type.ElementType); } else { LBBaseType baseType; if (TryGetBaseType(type.Type, out baseType)) { // 基本类型 | Base type type.InitBaseType(baseType); } else { LBType customType; if (TryGetCustomType(type.Type, out customType)) { // 自定义结构 | Custom type type.InitCustomType(customType); } else { // 未知类型 | Unknown type throw new Exception("Unknown type:\"" + type.Type + "\""); } } } }
/// <param name="lbType">判断是否是自定义类型 并获取该类型 | If it is a custem type then get it</param> public static bool TryGetCustomType(string name, out LBType lbType) { if (customTypeDict.TryGetValue(name, out lbType)) { return(true); } return(false); }
/// <summary> 添加一个自定义类型 | Add a custom type </summary> /// <param name="lbType"> LB类型 | LBType</param> public static void AddCustomType(LBType lbType) { if (!customTypeDict.ContainsKey(lbType.Name)) { customTypeDict.Add(lbType.Name, lbType); } else { string error = "Custom type [{0}] already exists."; error = string.Format(error, lbType.Name); throw new ArgumentException(error); } }
public void InitArray(LBType elementType) { IsArray = true; ElementType = elementType; }