Created
April 12, 2013 13:09
-
-
Save leppie/5371877 to your computer and use it in GitHub Desktop.
Uncompiled, untested, just written blindly :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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