本文整理汇总了C#中System.Reflection.Emit.ILGenerator.GetRVAFixups方法的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator.GetRVAFixups方法的具体用法?C# ILGenerator.GetRVAFixups怎么用?C# ILGenerator.GetRVAFixups使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.ILGenerator
的用法示例。
在下文中一共展示了ILGenerator.GetRVAFixups方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMethodBodyHelper
internal void CreateMethodBodyHelper(ILGenerator il)
{
// Sets the IL of the method. An ILGenerator is passed as an argument and the method
// queries this instance to get all of the information which it needs.
__ExceptionInfo[] excp;
int counter=0;
int[] filterAddrs;
int[] catchAddrs;
int[] catchEndAddrs;
Type[] catchClass;
int[] type;
int numCatch;
int start, end;
ModuleBuilder dynMod = (ModuleBuilder) m_module;
m_containingType.ThrowIfCreated();
if (m_bIsBaked)
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_MethodHasBody"));
}
if (il==null)
{
throw new ArgumentNullException("il");
}
if (il.m_methodBuilder != this && il.m_methodBuilder != null)
{
// you don't need to call CreateMethodBody when you get your ILGenerator
// through MethodBuilder::GetILGenerator.
//
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadILGeneratorUsage"));
}
ThrowIfShouldNotHaveBody();
if (il.m_ScopeTree.m_iOpenScopeCount != 0)
{
// There are still unclosed local scope
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_OpenLocalVariableScope"));
}
m_ubBody = il.BakeByteArray();
m_RVAFixups = il.GetRVAFixups();
m_mdMethodFixups = il.GetTokenFixups();
//Okay, now the fun part. Calculate all of the exceptions.
excp = il.GetExceptions();
m_numExceptions = CalculateNumberOfExceptions(excp);
if (m_numExceptions>0)
{
m_exceptions = new __ExceptionInstance[m_numExceptions];
for (int i=0; i<excp.Length; i++) {
filterAddrs = excp[i].GetFilterAddresses();
catchAddrs = excp[i].GetCatchAddresses();
catchEndAddrs = excp[i].GetCatchEndAddresses();
catchClass = excp[i].GetCatchClass();
// track the reference of the catch class
for (int j=0; j < catchClass.Length; j++)
{
if (catchClass[j] != null)
dynMod.GetTypeToken(catchClass[j]);
}
numCatch = excp[i].GetNumberOfCatches();
start = excp[i].GetStartAddress();
end = excp[i].GetEndAddress();
type = excp[i].GetExceptionTypes();
for (int j=0; j<numCatch; j++) {
int tkExceptionClass = 0;
if (catchClass[j] != null)
tkExceptionClass = dynMod.GetTypeToken(catchClass[j]).Token;
switch (type[j]) {
case __ExceptionInfo.None:
case __ExceptionInfo.Fault:
case __ExceptionInfo.Filter:
m_exceptions[counter++]=new __ExceptionInstance(start, end, filterAddrs[j], catchAddrs[j], catchEndAddrs[j], type[j], tkExceptionClass);
break;
case __ExceptionInfo.Finally:
m_exceptions[counter++]=new __ExceptionInstance(start, excp[i].GetFinallyEndAddress(), filterAddrs[j], catchAddrs[j], catchEndAddrs[j], type[j], tkExceptionClass);
break;
}
}
}
}
m_bIsBaked=true;
//.........这里部分代码省略.........
示例2: CreateMethodBodyHelper
internal void CreateMethodBodyHelper(ILGenerator il)
{
if (il == null)
{
throw new ArgumentNullException("il");
}
int num = 0;
ModuleBuilder module = this.m_module;
this.m_containingType.ThrowIfCreated();
if (this.m_bIsBaked)
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_MethodHasBody"));
}
if ((il.m_methodBuilder != this) && (il.m_methodBuilder != null))
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_BadILGeneratorUsage"));
}
this.ThrowIfShouldNotHaveBody();
if (il.m_ScopeTree.m_iOpenScopeCount != 0)
{
throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_OpenLocalVariableScope"));
}
this.m_ubBody = il.BakeByteArray();
this.m_RVAFixups = il.GetRVAFixups();
this.m_mdMethodFixups = il.GetTokenFixups();
__ExceptionInfo[] exceptions = il.GetExceptions();
this.m_numExceptions = this.CalculateNumberOfExceptions(exceptions);
if (this.m_numExceptions > 0)
{
this.m_exceptions = new __ExceptionInstance[this.m_numExceptions];
for (int i = 0; i < exceptions.Length; i++)
{
int[] filterAddresses = exceptions[i].GetFilterAddresses();
int[] catchAddresses = exceptions[i].GetCatchAddresses();
int[] catchEndAddresses = exceptions[i].GetCatchEndAddresses();
Type[] catchClass = exceptions[i].GetCatchClass();
for (int j = 0; j < catchClass.Length; j++)
{
if (catchClass[j] != null)
{
module.GetTypeTokenInternal(catchClass[j]);
}
}
int numberOfCatches = exceptions[i].GetNumberOfCatches();
int startAddress = exceptions[i].GetStartAddress();
int endAddress = exceptions[i].GetEndAddress();
int[] exceptionTypes = exceptions[i].GetExceptionTypes();
for (int k = 0; k < numberOfCatches; k++)
{
int exceptionClass = 0;
if (catchClass[k] != null)
{
exceptionClass = module.GetTypeTokenInternal(catchClass[k]).Token;
}
switch (exceptionTypes[k])
{
case 0:
case 1:
case 4:
this.m_exceptions[num++] = new __ExceptionInstance(startAddress, endAddress, filterAddresses[k], catchAddresses[k], catchEndAddresses[k], exceptionTypes[k], exceptionClass);
break;
case 2:
this.m_exceptions[num++] = new __ExceptionInstance(startAddress, exceptions[i].GetFinallyEndAddress(), filterAddresses[k], catchAddresses[k], catchEndAddresses[k], exceptionTypes[k], exceptionClass);
break;
}
}
}
}
this.m_bIsBaked = true;
if (module.GetSymWriter() != null)
{
SymbolToken method = new SymbolToken(this.MetadataTokenInternal);
ISymbolWriter symWriter = module.GetSymWriter();
symWriter.OpenMethod(method);
symWriter.OpenScope(0);
if (this.m_symCustomAttrs != null)
{
foreach (SymCustomAttr attr in this.m_symCustomAttrs)
{
module.GetSymWriter().SetSymAttribute(new SymbolToken(this.MetadataTokenInternal), attr.m_name, attr.m_data);
}
}
if (this.m_localSymInfo != null)
{
this.m_localSymInfo.EmitLocalSymInfo(symWriter);
}
il.m_ScopeTree.EmitScopeTree(symWriter);
il.m_LineNumberInfo.EmitLineNumberInfo(symWriter);
symWriter.CloseScope(il.ILOffset);
symWriter.CloseMethod();
}
}