public void Format(XpidlFile xpidlFile, TextWriter textWriter) { using (var codeDomProvider = CodeDomProvider.CreateProvider(Language)) { CodeNamespace codeNamespace = CreateCodeNamespace(xpidlFile); codeDomProvider.GenerateCodeFromNamespace(codeNamespace, textWriter, Options); } }
private static CodeNamespace CreateCodeNamespace(XpidlFile xpidlFile) { var codeNamespace = new CodeNamespace("Xpcom.Interop"); codeNamespace.Imports.Add(new CodeNamespaceImport("System")); codeNamespace.Imports.Add(new CodeNamespaceImport("System.Runtime.InteropServices")); // Add type declarations to namespace BuildCodeNamespace(codeNamespace, xpidlFile); return codeNamespace; }
private static void BuildCodeNamespace(CodeNamespace codeNamespace, XpidlFile xpidlFile) { for (Int32 i = 0; i < xpidlFile.ChildNodes.Count; ++i) { XpidlNode xpidlNode = xpidlFile.ChildNodes[i]; if (xpidlNode is XpidlInterface) { var xpidlInterface = (XpidlInterface) xpidlNode; CodeTypeDeclaration codeConstClassDeclaration; CodeTypeDeclaration codeInterfaceDeclaration = CraeteCodeInterfaceDeclaration(xpidlInterface, out codeConstClassDeclaration); if (codeConstClassDeclaration != null) { codeConstClassDeclaration.Comments.AddComment(String.Format("Constants for {0} ( \"{1}\" ) interface", xpidlInterface.Name, xpidlInterface.Uuid)); codeNamespace.Types.Add(codeConstClassDeclaration); } codeInterfaceDeclaration.Comments.AddPrecedingComments(xpidlFile, i); codeNamespace.Types.Add(codeInterfaceDeclaration); } } }