Microsoft.Cci.SourceEmitter.EmitString C# (CSharp) Method

EmitString() public method

Emits the given string to the current source line. If this is the first string on the line, indentation will be emitted before the string. Note, however, that if the string is empty nothing is emitted, not even indentation.
public EmitString ( string str ) : void
str string The string to emit.
return void
    public void EmitString(string str) {
      Contract.Requires(str != null);

      if (str.Length == 0) return;
      this.IndentIfAtStartOfNewLine();
      this.textWriter.Write(str);
    }

Usage Example

示例#1
0
    static void Main(string[] args) {
      if (args == null || args.Length == 0) {
        Console.WriteLine("usage: ILtoC [path]fileName.ext");
        return;
      }
      using (var host = new Host()) {
        var mscorlib = host.LoadUnitFrom("mscorlib.dll") as IAssembly;
        if (mscorlib == null || mscorlib is Dummy) {
          Console.WriteLine("mscorlib.dll must be in the same directory as "+args[0]);
          return;
        }
        var coreIdentity = host.CoreAssemblySymbolicIdentity; //Force the host to select the local mscorlib as the core assembly.
        if (coreIdentity != mscorlib.AssemblyIdentity) {
          Console.WriteLine("bug in host");
          return;
        }
        var module = host.LoadUnitFrom(args[0]) as IModule;
        if (module == null || module is Dummy) {
          Console.WriteLine(args[0]+" is not a PE file containing a CLR module or assembly.");
          return;
        }
        var moduleLocation = args[0];
        Contract.Assume(moduleLocation.Length > 0);

        PdbReader/*?*/ pdbReader = null;
        string pdbFileName = Path.ChangeExtension(moduleLocation, "pdb");
        if (File.Exists(pdbFileName)) {
          using (var pdbStream = File.OpenRead(pdbFileName)) {
            pdbReader = new PdbReader(pdbStream, host);
          }
        }
        var cfile = Path.ChangeExtension(moduleLocation, ".c");
        var hfile = Path.ChangeExtension(moduleLocation, ".h");
        var moduleFileName = Path.GetFileName(moduleLocation);
        Contract.Assume(moduleFileName != null && moduleFileName.Length > 0);
        string location = Path.GetFullPath(moduleLocation).Replace(moduleFileName, ""); ;
        using (var cStreamWriter = File.CreateText(cfile)) {
          using (var hStreamWriter = File.CreateText(hfile)) {
            var cEmitter = new SourceEmitter(cStreamWriter);
            cEmitter.EmitString("#include \"");
            cEmitter.EmitString(hfile);
            cEmitter.EmitString("\"");
            cEmitter.EmitNewLine();
            var hEmitter = new SourceEmitter(hStreamWriter);
            new Translator(host, module, mscorlib, cEmitter, hEmitter, location, pdbReader).TranslateToC();
          }
        }
      }
    }