Update if expr and dynamic method name
This commit is contained in:
parent
2a0e92eaff
commit
78124ea282
|
@ -29,6 +29,10 @@ namespace AssemblyData.methodsrewriter {
|
||||||
this.methodDefinition = methodDefinition;
|
this.methodDefinition = methodDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool hasInstructions() {
|
||||||
|
return methodDefinition.Body != null && methodDefinition.Body.Instructions.Count != 0;
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString() {
|
public override string ToString() {
|
||||||
return methodDefinition.ToString();
|
return methodDefinition.ToString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,10 +163,10 @@ namespace AssemblyData.methodsrewriter {
|
||||||
return newMethodInfo.rewrittenMethod;
|
return newMethodInfo.rewrittenMethod;
|
||||||
}
|
}
|
||||||
|
|
||||||
string getDelegateMethodName(string methodName) {
|
string getDelegateMethodName(MethodBase method) {
|
||||||
string name = null;
|
string name = null;
|
||||||
do {
|
do {
|
||||||
name = string.Format(" {0} DMN {1:X8} ", methodName, Utils.getRandomUint());
|
name = string.Format(" {0} {1:X8} DMN {2:X8} ", method.Name, method.MetadataToken, Utils.getRandomUint());
|
||||||
} while (delegateNameToNewMethodInfo.ContainsKey(name));
|
} while (delegateNameToNewMethodInfo.ContainsKey(name));
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ namespace AssemblyData.methodsrewriter {
|
||||||
public void createMethod(MethodBase realMethod) {
|
public void createMethod(MethodBase realMethod) {
|
||||||
if (realMethodToNewMethod.ContainsKey(realMethod))
|
if (realMethodToNewMethod.ContainsKey(realMethod))
|
||||||
return;
|
return;
|
||||||
var newMethodInfo = new NewMethodInfo(realMethod, newMethodInfos.Count, getDelegateMethodName(realMethod.Name), getDelegateMethodName(realMethod.Name));
|
var newMethodInfo = new NewMethodInfo(realMethod, newMethodInfos.Count, getDelegateMethodName(realMethod), getDelegateMethodName(realMethod));
|
||||||
newMethodInfos.Add(newMethodInfo);
|
newMethodInfos.Add(newMethodInfo);
|
||||||
delegateNameToNewMethodInfo[newMethodInfo.delegateMethodName] = newMethodInfo;
|
delegateNameToNewMethodInfo[newMethodInfo.delegateMethodName] = newMethodInfo;
|
||||||
delegateNameToNewMethodInfo[newMethodInfo.rewrittenMethodName] = newMethodInfo;
|
delegateNameToNewMethodInfo[newMethodInfo.rewrittenMethodName] = newMethodInfo;
|
||||||
|
@ -182,7 +182,7 @@ namespace AssemblyData.methodsrewriter {
|
||||||
|
|
||||||
var moduleInfo = Resolver.loadAssembly(realMethod.Module);
|
var moduleInfo = Resolver.loadAssembly(realMethod.Module);
|
||||||
var methodInfo = moduleInfo.getMethod(realMethod);
|
var methodInfo = moduleInfo.getMethod(realMethod);
|
||||||
if (!methodInfo.methodDefinition.HasBody || methodInfo.methodDefinition.Body.Instructions.Count == 0)
|
if (!methodInfo.hasInstructions())
|
||||||
throw new ApplicationException(string.Format("Method {0} ({1:X8}) has no body", methodInfo.methodDefinition, methodInfo.methodDefinition.MetadataToken.ToUInt32()));
|
throw new ApplicationException(string.Format("Method {0} ({1:X8}) has no body", methodInfo.methodDefinition, methodInfo.methodDefinition.MetadataToken.ToUInt32()));
|
||||||
|
|
||||||
var codeGenerator = new CodeGenerator(this, newMethodInfo.delegateMethodName);
|
var codeGenerator = new CodeGenerator(this, newMethodInfo.delegateMethodName);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user