public string UpdateUDT(string udtFileContents, string category, string identifier, string newcat, string newident) { StringReader udtsr = new StringReader(udtFileContents); UDTCompiler udtCompiler = new UDTCompiler(); udtCompiler.Compile(udtsr); foreach (DataType dt in udtCompiler.DefinedTypes) { if (dt.Category == category && dt.Identifier == identifier) { if (newcat != null) { dt.Category = newcat; } if (newident != null) { dt.Identifier = newident; } } } UDTWriter udtWriter = new UDTWriter(); udtWriter.Types.AddRange(udtCompiler.DefinedTypes.OfType <UserDefinedType>()); StringBuilder sb = new StringBuilder(); udtWriter.Write(new StringWriter(sb)); return(sb.ToString()); }
public void ExportUDTs(IEnumerable <UserDefinedType> list, string file) { UDTWriter udtWriter = new UDTWriter(); foreach (UserDefinedType udt in list) { udtWriter.Types.Add(udt); } lock (s_udtLock) udtWriter.Write(file); }
// Writes the UDT and mapping files to the specified path, containing the specified types and mappings. private void WriteMappingsTo(string path, IEnumerable <UserDefinedType> userDefinedTypes, IEnumerable <TypeMapping> userDefinedMappings) { // Determine the paths to the UDT and mapping files string udtFilePath = Path.Combine(path, "UserDefinedTypes.ecaidl"); string mappingFilePath = Path.Combine(path, "UserDefinedMappings.ecamap"); // Create the writers to generate the files UDTWriter udtWriter = new UDTWriter(); MappingWriter mappingWriter = new MappingWriter(); // Add the UDTs and mappings to the writers udtWriter.Types.AddRange(userDefinedTypes); mappingWriter.Mappings.AddRange(userDefinedMappings); // Generate the files udtWriter.Write(udtFilePath); mappingWriter.Write(mappingFilePath); }