internal XMLConverter(XmlType type, string excel_file) { xml_type = type; e_fname = excel_file; dir =(excel_file==null || excel_file=="")? "":Directory.GetParent(e_fname).FullName+"\\"; switch (type) { case XmlType.Index: xml_fname = "index.xml"; break; case XmlType.TaskList: xml_fname = "task.xml"; break; case XmlType.Master: xml_fname = "master.xml"; break; case XmlType.Dpr: xml_fname = Path.GetFileNameWithoutExtension(e_fname) + ".dprx"; break; } data = new DataSet(); if (e_fname == null || e_fname == "") return; data.DataSetName = "dockmaker.net"; try { book = Workbook.Open(e_fname); } catch (Exception ex) { throw ex; } }
private TerrainListViewItem FindParentItem(XmlType node) { TerrainListViewItem result; result = null; foreach (TerrainListViewItem item in Items) { if (item.Node == node) { result = item; } } return(result); }
static bool GetNameAndTypeRef(ref TypeReference elementType, string namespaceURI, ref string localname, ILContext context, IXmlLineInfo lineInfo) { var dotIdx = localname.IndexOf('.'); if (dotIdx > 0) { var typename = localname.Substring(0, dotIdx); localname = localname.Substring(dotIdx + 1); elementType = new XmlType(namespaceURI, typename, null).GetTypeReference(context.Body.Method.Module, lineInfo); return(true); } return(false); }
/// <summary> /// Initializes a new instance of the <see cref="UserType"/> class. /// </summary> /// <param name="symbol">The symbol we are generating this user type from.</param> /// <param name="xmlType">The XML description of the type.</param> /// <param name="nameSpace">The namespace it belongs to.</param> /// <param name="factory">User type factory that contains this element.</param> public UserType(Symbol symbol, XmlType xmlType, string nameSpace, UserTypeFactory factory) { Symbol = symbol; Factory = factory; InnerTypes = new List <UserType>(); DerivedClasses = new HashSet <UserType>(); typeNameCache = SimpleCache.CreateStruct(() => GetTypeName()); fullTypeNameCache = SimpleCache.CreateStruct(() => GetFullTypeName()); constructorNameCache = SimpleCache.CreateStruct(() => GetConstructorName()); namespaceCache = SimpleCache.CreateStruct(() => GetNamespace(nameSpace)); membersCache = SimpleCache.CreateStruct(() => GetMembers().ToArray()); constructorsCache = SimpleCache.CreateStruct(() => GetConstructors().ToArray()); baseClassCache = SimpleCache.CreateStruct(() => GetBaseClass(Symbol)); memoryBufferOffsetCache = SimpleCache.CreateStruct(() => GetMemoryBufferOffset()); }
public string GetPathName() { string text = name; XmlType nextParent = parent; while (nextParent != null) { if (!nextParent.IsArrayElement()) { text = nextParent.name + "/" + text; } nextParent = nextParent.parent; } return(text); }
public int GetDepth() { XmlType temp = parent; int depth = 0; while (temp != null) { if (!temp.IsArrayElement()) { ++depth; } temp = temp.parent; } return(depth); }
/// <summary> /// 通过xml文件路径获取某个节点的值 /// </summary> /// <param name="path">节点路径 例:/root/username</param> /// <param name="xmlValue">xml文件名或者xml文档</param> /// <param name="type">xml文档类型 参照XmlType</param> /// <returns></returns> public static string GetNodeValue(string path, string xmlValue, XmlType type) { string value = string.Empty; try { XmlNode node = GetNode(path, xmlValue, type); value = node.InnerText; } catch (Exception ee) { value = "错误:" + ee.Message; } return(value); }
public void BindingIsResolvedAsBindingExtension() // https://github.com/xamarin/Microsoft.Maui.Controls/issues/3606#issuecomment-422377338 { var bindingType = XamlParser.GetElementType(new XmlType("http://schemas.microsoft.com/dotnet/2021/maui", "Binding", null), null, null, out var ex); Assert.That(ex, Is.Null); Assert.That(bindingType, Is.EqualTo(typeof(BindingExtension))); var module = ModuleDefinition.CreateModule("foo", new ModuleParameters() { AssemblyResolver = new MockAssemblyResolver(), Kind = ModuleKind.Dll, }); var bindingTypeRef = new XmlType("http://schemas.microsoft.com/dotnet/2021/maui", "Binding", null).GetTypeReference(module, null); Assert.That(bindingType.FullName, Is.EqualTo("Microsoft.Maui.Controls.Xaml.BindingExtension")); }
public XmlTypeUserControl(XmlType type) { _xmlType = type; InitializeComponent(); XmlTypeNameLabel.Content = $"Type: {_xmlType.XType.Name}"; XmlTypeDescriptionLabel.Content = $"Description: {_xmlType.Description}"; foreach (var xmlProperty in _xmlType.XmlProperties) { XmlPropertiesListBox.Items.Add(new ListBoxItem { Content = xmlProperty }); } }
/// <summary> /// 读取XML资源到DataSet中 /// </summary> /// <param name="source">XML资源,文件为路径,否则为XML字符串</param> /// <param name="xmlType">XML资源类型</param> /// <returns>DataSet</returns> public static DataSet GetDataSet(string source, XmlType xmlType) { DataSet ds = new DataSet(); if (xmlType == XmlType.File) { ds.ReadXml(source); } else { XmlDocument xd = new XmlDocument(); xd.LoadXml(source); XmlNodeReader xnr = new XmlNodeReader(xd); ds.ReadXml(xnr); } return ds; }
/// <summary> /// 读取XML资源到DataSet中 /// </summary> /// <param name="source">XML资源,文件为路径,否则为XML字符串</param> /// <param name="xmlType">XML资源类型</param> /// <returns>DataSet</returns> public static DataSet GetDataSet(string source, XmlType xmlType) { DataSet ds = new DataSet(); if (xmlType == XmlType.File) { ds.ReadXml(source); } else { XmlDocument xd = XMLLoad(source); XmlNodeReader xnr = new XmlNodeReader(xd); ds.ReadXml(xnr); } return(ds); }
/// <summary> /// 读取XML资源到DataTable中 /// </summary> /// <param name="source">XML资源,文件为路径,否则为XML字符串</param> /// <param name="xmlType">XML资源类型:文件,字符串</param> /// <param name="tableName">表名称</param> /// <returns>DataTable</returns> public static DataTable GetTable(string source, XmlType xmlType, string tableName) { DataSet ds = new DataSet(); if (xmlType == XmlType.File) { ds.ReadXml(source); } else { XmlDocument xd = XMLLoad(source); XmlNodeReader xnr = new XmlNodeReader(xd); ds.ReadXml(xnr); } return(ds.Tables[tableName]); }
/// <summary> /// 实例化XmlHelper对象 /// </summary> /// <param name="xmlFilePath">Xml文件的相对路径</param> public XmlHelper(XmlType xmltype, string xmlString) { switch (xmltype) { case XmlType.xmlPath: //获取XML文件的绝对路径 _filePath = System.AppDomain.CurrentDomain.BaseDirectory + xmlString; break; case XmlType.xmlString: XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xmlString); this.Xml = xmlDoc; break; } }
/// <summary> /// 读取XML资源中指定的DataTable的指定行指定列的值 /// </summary> /// <param name="source">XML资源</param> /// <param name="xmlType">XML资源类型:文件,字符串</param> /// <param name="tableName">表名</param> /// <param name="rowIndex">行号</param> /// <param name="colIndex">列号</param> /// <returns>值,不存在时返回Null</returns> public static object GetTableCell(string source, XmlType xmlType, string tableName, int rowIndex, int colIndex) { DataSet ds = new DataSet(); if (xmlType == XmlType.File) { ds.ReadXml(source); } else { XmlDocument xd = XMLLoad(source); XmlNodeReader xnr = new XmlNodeReader(xd); ds.ReadXml(xnr); } return(ds.Tables[tableName].Rows[rowIndex][colIndex]); }
async Task <Object> ReadXml(string fileName, XmlType type) { StorageFile file = null; StorageFolder folder = null; if (type == XmlType.LEVEL || type == XmlType.TIERS) { folder = Windows.ApplicationModel.Package.Current.InstalledLocation; folder = await folder.GetFolderAsync("Levels"); } else if (type == XmlType.HIGHSCORE) { folder = ApplicationData.Current.LocalFolder; folder = await folder.GetFolderAsync("Meta"); } file = await folder.GetFileAsync(fileName); Object returnValue = null; string data; using (IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read)) { using (Stream inStream = Task.Run(() => readStream.AsStreamForRead()).Result) { using (StreamReader reader = new StreamReader(inStream)) { data = reader.ReadToEnd(); } } } if (type == XmlType.LEVEL) { returnValue = ExtractLevelData(data); } else if (type == XmlType.HIGHSCORE) { returnValue = ExtractScoreData(data); } else if (type == XmlType.TIERS) { returnValue = ExtractTierData(data); } return(returnValue); }
public static bool TryGetTypeReference(this XmlType xmlType, ModuleDefinition module, IXmlLineInfo xmlInfo, out TypeReference typeReference) { IList <XmlnsDefinitionAttribute> xmlnsDefinitions = null; lock (_nsLock) { if (!s_xmlnsDefinitions.TryGetValue(module, out xmlnsDefinitions)) { xmlnsDefinitions = GatherXmlnsDefinitionAttributes(module); } } var typeArguments = xmlType.TypeArguments; TypeReference type = xmlType.GetTypeReference(xmlnsDefinitions, module.Assembly.Name.Name, (typeInfo) => { string typeName = typeInfo.TypeName.Replace('+', '/'); //Nested types return(module.GetTypeDefinition((typeInfo.AssemblyName, typeInfo.ClrNamespace, typeName))); },
/// <summary> /// 读取XML资源到DataSet中 /// </summary> /// <param name="source">XML资源,文件为路径,否则为XML字符串</param> /// <param name="xmlType">XML资源类型</param> /// <returns>DataSet</returns> public static DataSet GetDataSet(string source, XmlType xmlType) { var dataSet = new DataSet(); if (xmlType == XmlType.File) { dataSet.ReadXml(source); } else { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(source); var xmlNodeReader = new XmlNodeReader(xmlDocument); dataSet.ReadXml(xmlNodeReader); } return(dataSet); }
/// <summary> /// 读取XML资源中指定的DataTable的指定行指定列的值 /// </summary> /// <param name="source">XML资源</param> /// <param name="xmlType">XML资源类型:文件,字符串</param> /// <param name="tableName">表名</param> /// <param name="rowIndex">行号</param> /// <param name="colIndex">列号</param> /// <returns>值,不存在时返回Null</returns> public static object GetTableCell(string source, XmlType xmlType, string tableName, int rowIndex, int colIndex) { var dataSet = new DataSet(); if (xmlType == XmlType.File) { dataSet.ReadXml(source); } else { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(source); var xmlNodeReader = new XmlNodeReader(xmlDocument); dataSet.ReadXml(xmlNodeReader); } return(dataSet.Tables[tableName].Rows[rowIndex][colIndex]); }
/// <summary> /// 读取XML资源到DataTable中 /// </summary> /// <param name="source">XML资源,文件为路径,否则为XML字符串</param> /// <param name="xmlType">XML资源类型:文件,字符串</param> /// <param name="tableName">表名称</param> /// <returns>DataTable</returns> public static DataTable GetTable(string source, XmlType xmlType, string tableName) { var dataSet = new DataSet(); if (xmlType == XmlType.File) { dataSet.ReadXml(source); } else { var xmlDocument = new XmlDocument(); xmlDocument.LoadXml(source); var xmlNodeReader = new XmlNodeReader(xmlDocument); dataSet.ReadXml(xmlNodeReader); } return(dataSet.Tables[tableName]); }
/// <summary> /// 读取XML资源中的指定节点内容 /// </summary> /// <param name="source">XML资源</param> /// <param name="xmlType">XML资源类型:文件,字符串</param> /// <param name="nodeName">节点名称</param> /// <returns>节点内容</returns> public static string GetNodeValue(string source, XmlType xmlType, string nodeName) { var xmlDocument = new XmlDocument(); if (xmlType == XmlType.File) { xmlDocument.Load(source); } else { xmlDocument.LoadXml(source); } var documentElement = xmlDocument.DocumentElement; var selectSingleNode = documentElement?.SelectSingleNode("//" + nodeName); return(selectSingleNode?.InnerText); }
public IEnumerable <Instruction> ConvertFromString(string value, ILContext context, BaseNode node) { var module = context.Body.Method.Module; if (string.IsNullOrEmpty(value)) { goto error; } var split = value.Split(':'); if (split.Length > 2) { goto error; } XmlType xmlType; if (split.Length == 2) { xmlType = new XmlType(node.NamespaceResolver.LookupNamespace(split[0]), split[1], null); } else { xmlType = new XmlType(node.NamespaceResolver.LookupNamespace(""), split[0], null); } var typeRef = xmlType.GetTypeReference(module, (IXmlLineInfo)node); if (typeRef == null) { goto error; } var getTypeFromHandle = module.ImportReference(typeof(Type).GetMethod("GetTypeFromHandle", new[] { typeof(RuntimeTypeHandle) })); yield return(Instruction.Create(OpCodes.Ldtoken, module.ImportReference(typeRef))); yield return(Instruction.Create(OpCodes.Call, module.ImportReference(getTypeFromHandle))); yield break; error: throw new XamlParseException($"Cannot convert \"{value}\" into {typeof(Type)}", node); }
public void GenerateCheckMethodBody(XmlType xmlType) { _stringBuilder.AppendLine("// Replaces decimals in a XML file that are not correctly formatted according to the XML specification."); _stringBuilder.AppendLine("// Use case: Sometimes a decimal is given with thousands separators, e.g. \"1.000,00\" or \"1,000.00\". This will be"); _stringBuilder.AppendLine("// transformed to \"1000,00\" or \"1000.00\" to comply with the XML decimal specification."); _stringBuilder.AppendLine("// The decimal separator (point or comma) is kept as-is, since regular Xml implementations handle that well."); _stringBuilder.AppendLine($"var elementDecimalValue = {CodeGeneratorConstants.ELEMENT_CHECK_METHOD_ELEMENT_VARIABLE_NAME}.Value?.Trim();"); _stringBuilder.AppendLine("// In case there are multiple points or commas adjacent to eachother"); _stringBuilder.AppendLine($"if ({CodeGeneratorConstants.ELEMENT_CHECK_METHOD_ELEMENT_VARIABLE_NAME}.Nodes().Any(node => !(node is XText)))"); using (new CodeGeneratorBlockWrapper(_stringBuilder)) { _stringBuilder.AppendLine("// A decimal value should only have text nodes"); _stringBuilder.AppendLine("element.Remove();"); _stringBuilder.AppendLine("return;"); } _stringBuilder.AppendLine(@"elementDecimalValue = Regex.Replace(elementDecimalValue, ""\\.+"", ""."");"); _stringBuilder.AppendLine("elementDecimalValue = Regex.Replace(elementDecimalValue, \",+\", \",\");"); _stringBuilder.AppendLine("string commaSeparatedPattern = @\"^([0-9,]+[.]\\d*)$\";"); _stringBuilder.AppendLine("string pointSeparatedPattern = @\"^([0-9.]+[,]\\d*)$\";"); _stringBuilder.AppendLine("string numericalPattern = @\"^(\\s*[0-9.,]+\\s*)$\";"); _stringBuilder.AppendLine("if (Regex.IsMatch(elementDecimalValue, commaSeparatedPattern))"); using (new CodeGeneratorBlockWrapper(_stringBuilder)) { _stringBuilder.AppendLine($"{CodeGeneratorConstants.ELEMENT_CHECK_METHOD_ELEMENT_VARIABLE_NAME}.Value = elementDecimalValue.Replace(\",\", string.Empty);"); } _stringBuilder.AppendLine("else if (Regex.IsMatch(elementDecimalValue, pointSeparatedPattern))"); using (new CodeGeneratorBlockWrapper(_stringBuilder)) { _stringBuilder.AppendLine($"{CodeGeneratorConstants.ELEMENT_CHECK_METHOD_ELEMENT_VARIABLE_NAME}.Value = elementDecimalValue.Replace(\".\", string.Empty);"); } _stringBuilder.AppendLine("else if (string.IsNullOrWhiteSpace(elementDecimalValue))"); using (new CodeGeneratorBlockWrapper(_stringBuilder)) { _stringBuilder.AppendLine("// In cases where no actual value is specified for the numerical value, the element is removed"); _stringBuilder.AppendLine("// to avoid parser errors downstream"); _stringBuilder.AppendLine($"{CodeGeneratorConstants.ELEMENT_CHECK_METHOD_ELEMENT_VARIABLE_NAME}.Remove();"); } _stringBuilder.AppendLine("else if (!Regex.IsMatch(elementDecimalValue, numericalPattern))"); using (new CodeGeneratorBlockWrapper(_stringBuilder)) { _stringBuilder.AppendLine("// When it's not numeric at all it should be removed"); _stringBuilder.AppendLine($"{CodeGeneratorConstants.ELEMENT_CHECK_METHOD_ELEMENT_VARIABLE_NAME}.Remove();"); } }
public void GenerateTypeCheckingMethod(XmlType xmlType) { var checkMethodName = XmlCodeGeneratorMethodNameProvider.GetNameForAttributeCheckMethod(xmlType); _stringBuilder.AppendLine($"private void {checkMethodName}(XAttribute {ATTRIBUTE_VARIABLE_NAME})"); using (new CodeGeneratorBlockWrapper(_stringBuilder)) { var enumerationType = xmlType as XmlEnumerationType; if (enumerationType != null) { GenerateEnumerationAttributeCheckMethod(enumerationType); } else { _stringBuilder.AppendLine("// Only attributes with enumeration restriction are currently supported for validation"); } } }
/// <summary> /// 根据传入的xml字符串或xml文件路径初始化一个实例 /// </summary> /// <param name="xml">xml字符串或xml文件路径</param> /// <param name="type">初始化类型</param> public XmlHelper(string xml,XmlType type) { try { if (type == XmlType.Path) { xmldoc.Load(xml); path = xml; } else xmldoc.LoadXml(xml); root = xmldoc.DocumentElement; } catch (Exception ex) { throw new Exception(string.Format("初始化xml失败,原因如下:{0}", ex.Message)); } }
public void GetElementTypeExtension() { tlog.Debug(tag, $"GetElementTypeExtension START"); try { var xt = new XmlType("http://tizen.org/Tizen.NUI/2018/XAML", "View", null); var t = XamlParser.GetElementTypeExtension(xt, null, typeof(UIElement).Assembly); Assert.IsNull(t, "Should be null"); } catch (Exception e) { tlog.Debug(tag, e.Message.ToString()); Assert.Fail("Caught Exception : Failed!"); } tlog.Debug(tag, $"GetElementTypeExtension END"); }
public string Check(XmlType xmlType, IgnoreNode ignoreNodeRoot, bool checkExtraField = false) { if (xmlType == null || ignoreNodeRoot == null) { return(string.Empty); } string error = string.Empty; if (xmlType.name != name) { if (checkExtraField && !ignoreNodeRoot.IsIgnored(xmlType)) { error += "<color=yellow> XML多填了: " + GetPathName() + GetPosition() + "</color>\n"; } } else { Dictionary <string, XmlType> dicChildren = new Dictionary <string, XmlType>(); xmlType.GetAllMembers(dicChildren); for (int i = 0; i < listChildren.Count; ++i) { Node child = listChildren[i]; XmlType childXmlType = xmlType.GetMember(child.name); if (childXmlType == null) { if (checkExtraField && !ignoreNodeRoot.IsIgnored(xmlType, child.name)) { error += "<color=yellow> XML多填了: " + child.GetPathName() + child.GetPosition() + "</color>\n"; } continue; } dicChildren.Remove(child.name); error += child.Check(childXmlType, ignoreNodeRoot, checkExtraField); } foreach (KeyValuePair <string, XmlType> temp in dicChildren) { if (!temp.Value.IsArray() && !ignoreNodeRoot.IsIgnored(temp.Value)) { error += "<color=red> XML少填了: " + GetPathName() + "/" + temp.Value.name + GetPosition() + "</color>\n"; } } } return(error); }
/// <summary> /// 导出xml /// </summary> /// <param name="outString"></param> /// <param name="type"></param> /// <returns></returns> public string Save(string outString, XmlType type) { try { if (type == XmlType.File) { xmlDoc.Save(outString); return(outString); } else { return(xmlDoc.InnerXml); } } catch (System.Exception ex) { throw ex; } }
/// <summary> /// 读取XML资源中的指定节点属性的内容 /// </summary> /// <param name="source">XML资源</param> /// <param name="xmlType">XML资源类型:文件,字符串</param> /// <param name="nodeName">属性节点名称</param> /// <param name="attributeString"></param> /// <returns>节点内容</returns> public static string GetNodeAttributeValue(string source, XmlType xmlType, string nodeName, string attributeString) { var xmlDocument = new XmlDocument(); if (xmlType == XmlType.File) { xmlDocument.Load(source); } else { xmlDocument.LoadXml(source); } var documentElement = xmlDocument.DocumentElement; var selectSingleNode = (XmlElement)documentElement?.SelectSingleNode("//" + nodeName); //if (selectSingleNode != null) return(selectSingleNode?.GetAttribute(attributeString)); }
public string InitialiseFromCollection(string collectionName) { var propertyEquals = string.Format("\t\t\t{0} = ", GetCodeName()); if (IsElementValue) { return(propertyEquals + "element.Value;"); } var accessorMethod = "SingleOrDefault()"; if (BindedType != null) { accessorMethod = string.Format("SingleOrDefault() ?? new Null{0}()", GetCodeType()); } if (IsList) { accessorMethod = "ToList()"; } var propertyInitialisationStatment = string.Format("element.{3}().Where(e => e.Name == \"{0}\").Select(e => {1}).{2}", XmlName, XElementToValue("e"), accessorMethod, collectionName ); if (IsParsable) { return(propertyEquals + string.Format("string.IsNullOrEmpty({0}) ? null : ({1}?){1}.Parse({0});", propertyInitialisationStatment, XmlType.TrimEnd('?') )); } else { propertyInitialisationStatment = propertyEquals + propertyInitialisationStatment; } propertyInitialisationStatment += ";"; return(propertyInitialisationStatment); }
/// <summary> /// 根据传入的xml字符串或xml文件路径初始化一个实例 /// </summary> /// <param name="xml">xml字符串或xml文件路径</param> /// <param name="type">初始化类型</param> public XmlHelper(string xml, XmlType type) { try { if (type == XmlType.Path) { xmldoc.Load(xml); path = xml; } else { xmldoc.LoadXml(xml); } root = xmldoc.DocumentElement; } catch (Exception ex) { throw new Exception(string.Format("初始化xml失败,原因如下:{0}", ex.Message)); } }
public void SetArrayItem(XmlType xmlType) { if (xmlType == null) { Debug.LogError("Error: CheckXML.SetArray() " + GetLogName() + " xmlType is null"); return; } if (arrayElement != null) { Debug.LogError("Error: CheckXML.SetArray() " + GetLogName() + " already has arrayElement: " + arrayElement); return; } if (dicMembers.Count > 0) { Debug.LogError("Error: CheckXML.SetArray() " + GetLogName() + " dicMembers is not empty: " + dicMembers.Count); dicMembers.Clear(); } arrayElement = xmlType; arrayElement.parent = this; }
/// <summary> /// 得到XmlHelper类实例 /// </summary> /// <param name="fileName">文件名</param> /// <param name="type">xml文件类型</param> /// <returns>XmlManage</returns> public static XmlHelper Instance(string fileName, XmlType type) { XmlHelper manage = new XmlHelper(); switch (type) { case XmlType.None: manage.Load(fileName); return(manage); case XmlType.File: manage.Load(fileName); return(manage); case XmlType.Content: manage.LoadXml(fileName); return(manage); } return(manage); }
public static XmlDocument XMLLoad(string XmlNodeStr, XmlType xmlType) { XmlDocument xd = new XmlDocument(); StringBuilder str = new StringBuilder(); if (xmlType == XmlType.String) { str.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>"); str.Append(XmlNodeStr); try { xd.LoadXml(str.ToString()); } catch (Exception ex) { RURO.Common.LogHelper.WriteError(ex); xd = null; } } return(xd); }
public static void LoadType(Type type) { if (typeof(XmlBaseType).IsAssignableFrom(type)) { var xmlType = new XmlType(type); if (_type_xmlType.ContainsKey(type)) throw new TestLibsException($"Found duped xmlType for type: {type}"); _type_xmlType.Add(type, xmlType); _xmlType_assignableXmlTypes.Add(xmlType, new List<XmlType>()); foreach (var key in _xmlType_assignableXmlTypes.Keys) { if (key.XType.IsAssignableFrom(type)) { _xmlType_assignableXmlTypes[key].Add(xmlType); } } } }
/// <summary> /// Adds the symbol to user type factory and generates the user type. /// </summary> /// <param name="symbol">The non-template symbol.</param> /// <param name="type">The XML type description.</param> /// <param name="nameSpace">The namespace.</param> /// <param name="generationFlags">The user type generation flags.</param> /// <returns>Generated user type for the specified symbol.</returns> internal UserType AddSymbol(Symbol symbol, XmlType type, string nameSpace, UserTypeGenerationFlags generationFlags) { UserType userType; if (symbol.Tag == SymTagEnum.SymTagEnum) { userType = new EnumUserType(symbol, nameSpace); } else if (symbol.Tag == SymTagEnum.SymTagExe) { userType = new GlobalsUserType(symbol, type, nameSpace); } else if (generationFlags.HasFlag(UserTypeGenerationFlags.GeneratePhysicalMappingOfUserTypes)) { userType = new PhysicalUserType(symbol, type, nameSpace); } else { userType = new UserType(symbol, type, nameSpace); } symbol.UserType = userType; return userType; }
public XmlAttribute(XmlType type) { this._XmlType = type; }
public static void LoadType(Type type) { if (typeof(XmlBaseType).IsAssignableFrom(type)) { var xmlType = new XmlType(type); if (_type_xmlType.ContainsKey(type)) throw new TestLibsException($"Found duped xmlType for type: {type}"); _type_xmlType.Add(type, xmlType); _xmlType_assignableXmlTypes.Add(xmlType, new List<XmlType>()); foreach (var key in _xmlType_assignableXmlTypes.Keys) { if (key.XType.IsAssignableFrom(type) && !type.IsAbstract) { _xmlType_assignableXmlTypes[key].Add(xmlType); } } foreach (var key in _xmlType_assignableXmlTypes.Keys) { if (type.IsAssignableFrom(key.XType) && !key.XType.IsAbstract) { _xmlType_assignableXmlTypes[xmlType].Add(key); } } } if (typeof(CommandManagerBase).IsAssignableFrom(type)) { var commandManager = new CommandManager(type); _managers.Add(commandManager); } }
/// <summary> /// Initializes a new instance of the <see cref="GlobalsUserType"/> class. /// </summary> /// <param name="symbol">The symbol we are generating this user type from.</param> /// <param name="xmlType">The XML description of the type.</param> /// <param name="nameSpace">The namespace it belongs to.</param> public GlobalsUserType(Symbol symbol, XmlType xmlType, string nameSpace) : base(symbol, xmlType, nameSpace) { }
public XmlAttribute(XmlType type, string name) { this._XmlType = type; this._Name = name; }
/// <summary> /// 读取XML资源中指定的DataTable的指定行指定列的值 /// </summary> /// <param name="source">XML资源</param> /// <param name="xmlType">XML资源类型:文件,字符串</param> /// <param name="tableName">表名</param> /// <param name="rowIndex">行号</param> /// <param name="colIndex">列号</param> /// <returns>值,不存在时返回Null</returns> public static object GetTableCell(string source, XmlType xmlType, string tableName, int rowIndex, int colIndex) { DataSet ds = new DataSet(); if (xmlType == XmlType.File) { ds.ReadXml(source); } else { XmlDocument xd = new XmlDocument(); xd.LoadXml(source); XmlNodeReader xnr = new XmlNodeReader(xd); ds.ReadXml(xnr); } return ds.Tables[tableName].Rows[rowIndex][colIndex]; }
/// <summary> /// 读取XML资源到DataTable中 /// </summary> /// <param name="source">XML资源,文件为路径,否则为XML字符串</param> /// <param name="xmlType">XML资源类型:文件,字符串</param> /// <param name="tableName">表名称</param> /// <returns>DataTable</returns> public static DataTable GetTable(string source, XmlType xmlType, string tableName) { DataSet ds = new DataSet(); if (xmlType == XmlType.File) { ds.ReadXml(source); } else { XmlDocument xd = new XmlDocument(); xd.LoadXml(source); XmlNodeReader xnr = new XmlNodeReader(xd); ds.ReadXml(xnr); } return ds.Tables[tableName]; }
/// <summary> /// 读取XML资源中的指定节点内容 /// </summary> /// <param name="source">XML资源</param> /// <param name="xmlType">XML资源类型:文件,字符串</param> /// <param name="nodeName">节点名称</param> /// <returns>节点内容</returns> public static object GetNodeValue(string source, XmlType xmlType, string nodeName) { XmlDocument xd = new XmlDocument(); if (xmlType == XmlType.File) { xd.Load(source); } else { xd.LoadXml(source); } XmlElement xe = xd.DocumentElement; XmlNode xn = xe.SelectSingleNode("//" + nodeName); if (xn != null) { return xn.InnerText; } else { return null; } }
public XmlAttribute(XmlType type, string name, string culture) { this._XmlType = type; this._Name = name; this._Culture = culture; }
public XmlAttribute() { this._XmlType = Xml.XmlType.Element; }
/// <summary> /// Initializes a new instance of the <see cref="TemplateUserType" /> class. /// </summary> /// <param name="symbol">The symbol we are generating this user type from.</param> /// <param name="xmlType">The XML description of the type.</param> /// <param name="nameSpace">The namespace it belongs to.</param> /// <param name="factory">The user type factory.</param> public TemplateUserType(Symbol symbol, XmlType xmlType, string nameSpace, UserTypeFactory factory) : base(symbol, xmlType, nameSpace) { UpdateTemplateArguments(factory); ExportStaticFields = false; }
/// <summary> /// Adds the symbols to user type factory and generates the user types. /// </summary> /// <param name="symbols">The template symbols grouped around the same template type.</param> /// <param name="type">The XML type description.</param> /// <param name="nameSpace">The namespace.</param> /// <param name="generationFlags">The user type generation flags.</param> /// <returns>Generated user types for the specified symbols.</returns> internal IEnumerable<UserType> AddSymbols(IEnumerable<Symbol> symbols, XmlType type, string nameSpace, UserTypeGenerationFlags generationFlags) { if (!type.IsTemplate && symbols.Count() > 1) throw new Exception("Type has more than one symbol for " + type.Name); if (!type.IsTemplate) { yield return AddSymbol(symbols.First(), type, nameSpace, generationFlags); } else { // Bucketize template user types based on number of template arguments var buckets = new Dictionary<int, List<TemplateUserType>>(); foreach (Symbol symbol in symbols) { UserType userType = null; try { // We want to ignore "empty" generic classes (for now) if (symbol.Name == null || symbol.Size == 0) continue; // Generate template user type TemplateUserType templateType = new TemplateUserType(symbol, type, nameSpace, this); #if false // TODO: Verify if we want to use simple user type instead of template user type if (templateType.AllTemplateArguments.Count == 0) { // Template does not have arguments that can be used by generic // Make it specialized type userType = this.AddSymbol(symbol, null, moduleName, generationOptions); } else #endif { List<TemplateUserType> templates; symbol.UserType = templateType; if (!buckets.TryGetValue(templateType.AllTemplateArguments.Count, out templates)) buckets.Add(templateType.AllTemplateArguments.Count, templates = new List<TemplateUserType>()); templates.Add(templateType); } } catch (Exception ex) { // TODO: Verify if we need to add this as specialization if (ex.Message != "Wrongly formed template argument") throw; } if (userType != null) yield return userType; } // Add newly generated types foreach (List<TemplateUserType> templatesInBucket in buckets.Values) { // TODO: Verify that all templates in the list can be described by the same class (also do check for inner-types) // Sort Templates by Class Name. // This removes ambiguity caused by parallel type processing. // List<TemplateUserType> templates = templatesInBucket.OrderBy(t => t.Symbol.Name.Count(c => c == '*')) .ThenBy(t => t.Symbol.Name.Count(c => c == '<')) .ThenBy(t => t.Symbol.Name).ToList(); // Select best suited type for template TemplateUserType template = templates.First(); foreach (var specializedTemplate in templates) { var arguments = specializedTemplate.AllTemplateArguments; // Check if all arguments are different if (arguments.Distinct().Count() == arguments.Count()) { // Check if all arguments are simple user type bool simpleUserType = true; foreach (var argument in arguments) { var argumentSymbol = GlobalCache.GetSymbol(argument, specializedTemplate.Module); if (argumentSymbol.Tag != SymTagEnum.SymTagUDT || argumentSymbol.Name.Contains("<")) { simpleUserType = false; break; } } if (simpleUserType) { template = specializedTemplate; break; } // Check if none of the arguments is template user type bool noneIsTemplate = true; foreach (var argument in arguments) { var argumentSymbol = GlobalCache.GetSymbol(argument, specializedTemplate.Module); if (argumentSymbol.Tag == SymTagEnum.SymTagUDT && argumentSymbol.Name.Contains("<")) { noneIsTemplate = false; break; } } if (noneIsTemplate) { template = specializedTemplate; continue; } } // This one is as good as any... } // Move all types under the selected type foreach (var specializedTemplate in templates) { template.SpecializedTypes.Add(specializedTemplate); specializedTemplate.TemplateType = template; } yield return template; } } }
public XmlAttribute(string name) { this._XmlType = Xml.XmlType.Element; this._Name = name; }
/// <summary> /// Initializes a new instance of the <see cref="PhysicalUserType"/> class. /// </summary> /// <param name="symbol">The symbol we are generating this user type from.</param> /// <param name="xmlType">The XML description of the type.</param> /// <param name="nameSpace">The namespace it belongs to.</param> public PhysicalUserType(Symbol symbol, XmlType xmlType, string nameSpace) : base(symbol, xmlType, nameSpace) { }