/// <summary> /// 这个方法搞不好有点复杂,因为需要根据原语类型,复合类型和数组进行分别处理 /// </summary> /// <param name="fieldName"></param> /// <param name="meta"></param> /// <param name="value"></param> /// <returns></returns> private static XElement WrapType( ResourceInformation generateInfo, CsvFile csvInfo, string fieldName, ConvertMeta meta, List<string> value, bool isComplexCollection = false, int complexCollectionIndex = 0, MetadataField baseField = null) { MetadataField field = meta.FieldDictionary[fieldName]; XElement root = new XElement(fieldName); if (generateInfo.Metadatas.ContainsKey(field.Type)) { WrapComplexType(generateInfo, csvInfo, value, isComplexCollection, complexCollectionIndex, field, root); } else if (isComplexCollection) { WrapComplexCollectionType(csvInfo, value, complexCollectionIndex, field, root, baseField); } else if (field.IsCollection) { WrapCollectionType(generateInfo, csvInfo, value, field, root); } else { WrapPrimitiveType(csvInfo, value, field, root); } return root; }
/// <summary> /// 从TDR风格的Xml元数据文件中读取元数据 /// </summary> /// <param name="metadataFilePath"></param> public void ReadMetadataFromXml(string metadataFilePath) { XElement metadataElement = XElement.Load(metadataFilePath); if (metadataElement.Attribute(@"namespace") != null) { package = metadataElement.Attribute(@"namespace").Value; } foreach (XElement ele in metadataElement.Elements(@"struct")) { ConvertMeta meta = new ConvertMeta(ele); metadataDictionary.Add(meta.Name, meta); } foreach (XElement ele in metadataElement.Elements(@"macro")) { macros.Add(ele.Attribute("name").Value, Convert.ToInt32(ele.Attribute("value").Value)); } }