mirror of https://github.com/mono/CppSharp.git
c-sharpdotnetmonobindingsbridgecclangcpluspluscppsharpglueinteropparserparsingpinvokeswigsyntax-treevisitorsxamarinxamarin-bindings
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.8 KiB
70 lines
1.8 KiB
|
|
using System; |
|
using System.IO; |
|
using System.Collections.Generic; |
|
|
|
using System.CodeDom; |
|
|
|
namespace Mono.VisualC.Code { |
|
public class CodeUnit : CodeContainer { |
|
|
|
public string ManagedNamespace { get; set; } |
|
|
|
public CodeUnit () : base (string.Empty) |
|
{ |
|
} |
|
|
|
public virtual CodeCompileUnit WrapperToCodeDom () |
|
{ |
|
CodeCompileUnit ccu = new CodeCompileUnit (); |
|
Visit (ccu); |
|
|
|
return ccu; |
|
} |
|
|
|
internal protected override object InsideCodeCompileUnit (CodeCompileUnit ccu) |
|
{ |
|
CodeNamespace ns = new CodeNamespace (ManagedNamespace); |
|
ns.Imports.Add (new CodeNamespaceImport ("Mono.VisualC.Interop")); |
|
ccu.Namespaces.Add (ns); |
|
|
|
return ns; |
|
} |
|
|
|
internal protected override object InsideCodeNamespace (CodeNamespace ns) |
|
{ |
|
foreach (var atom in Atoms) |
|
atom.Visit (ns); |
|
|
|
return null; |
|
} |
|
|
|
public override string ToString () |
|
{ |
|
StringWriter str = new StringWriter (); |
|
Write (str); |
|
return str.ToString (); |
|
} |
|
|
|
public override void Write (TextWriter writer) |
|
{ |
|
writer.WriteLine ("//------------------------------------------------------------------------------"); |
|
writer.WriteLine ("// <auto-generated>"); |
|
writer.WriteLine ("// This code was generated by a tool."); |
|
writer.WriteLine ("// Runtime Version:{0}{1}//", Environment.Version, writer.NewLine); |
|
writer.WriteLine ("// Changes to this file may cause incorrect behavior and will be lost if"); |
|
writer.WriteLine ("// the code is regenerated."); |
|
writer.WriteLine ("// </auto-generated>"); |
|
writer.WriteLine ("//------------------------------------------------------------------------------{0}", writer.NewLine); |
|
|
|
base.Write (writer); |
|
} |
|
|
|
public virtual void Save (string fileName) |
|
{ |
|
using (StreamWriter stream = File.CreateText (fileName)) { |
|
Write (stream); |
|
} |
|
} |
|
} |
|
}
|
|
|