Created
February 5, 2012 15:21
-
-
Save awithy/1746060 to your computer and use it in GitHub Desktop.
This file contains 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
public class CecilAssembly : IILAssembly | |
{ | |
private readonly AssemblyDefinition _assemblyDefinition; | |
private readonly string _assemblyPath; | |
public CecilAssembly(string assemblyPath) | |
{ | |
_assemblyPath = assemblyPath; | |
_assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyPath); | |
} | |
public IEnumerable<IILMethod> FindAllNonCtorMethodsWithPrefix(string prefix) | |
{ | |
var typeDefinitions = _assemblyDefinition.MainModule.Types; | |
var typesInNamespaceToUpdate = typeDefinitions.Where(x => x.FullName.StartsWith(prefix)); | |
var typeMethodsToUpdate = typesInNamespaceToUpdate.SelectMany(x => x.Methods).Where(x => x.Name != ".ctor"); | |
return typeMethodsToUpdate.Select(x => new CecilMethod(x)); | |
} | |
public IILMethod FindMethod(string methodName) | |
{ | |
var methodDefinition = | |
_assemblyDefinition.MainModule.Types.SelectMany(x => x.Methods).Where( | |
x => x.DeclaringType + "." + x.Name == methodName).Single(); | |
return new CecilMethod(methodDefinition); | |
} | |
public void SaveToDisk() | |
{ | |
_assemblyDefinition.Write(_assemblyPath); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment