Skip to content

Instantly share code, notes, and snippets.

@leppie
Created April 12, 2013 13:09
Show Gist options
  • Save leppie/5371877 to your computer and use it in GitHub Desktop.
Save leppie/5371877 to your computer and use it in GitHub Desktop.
Uncompiled, untested, just written blindly :)
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Mono.Cecil;
namespace NamespaceRenamer
{
class Program
{
class Transform
{
public string Source, Target;
}
static Regex tx = new Regex("^(?<src>.+)=(?<tgt>.+)$", RegexOptions.Compiled);
static void Main(string[] args)
{
var assname = args[0];
var renames = new List<Transform>();
for (int i = 1; i < args.Length; i++)
{
var m = tx.Match(args[i]);
renames.Add(new Transform
{
Source = m.Groups["src"].Value,
Target = m.Groups["tgt"].Value,
});
}
var ass = AssemblyDefinition.ReadAssembly(assname);
foreach (var t in ass.MainModule.Types)
{
foreach (var r in renames)
{
if (t.Namespace.StartsWith(r.Source))
{
t.Namespace = t.Namespace.Replace(r.Source, r.Target);
}
}
}
ass.Write(assname);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment