本文整理汇总了C#中StackFrame.SetCodePos方法的典型用法代码示例。如果您正苦于以下问题:C# StackFrame.SetCodePos方法的具体用法?C# StackFrame.SetCodePos怎么用?C# StackFrame.SetCodePos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StackFrame
的用法示例。
在下文中一共展示了StackFrame.SetCodePos方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: JumpToErr
bool JumpToErr(CodeBody body, StackFrame frame, Exception err)
{
var posnow = frame.GetCode();
List<Mono.Cecil.Cil.ExceptionHandler> ehs = new List<ExceptionHandler>();
Mono.Cecil.Cil.ExceptionHandler ehNear = null;
int ehNearB = -1;
foreach (var eh in body.bodyNative.ExceptionHandlers)
{
if (eh.HandlerType == ExceptionHandlerType.Catch)
{
Type ehtype = GetType(eh.CatchType).TypeForSystem;
if (ehtype == err.GetType() || err.GetType().IsSubclassOf(ehtype))
//if(GetType(eh.CatchType)== environment.GetType(err.GetType()))
{
if (eh.TryStart.Offset <= posnow.Offset && eh.TryEnd.Offset >= posnow.Offset)
{
if (ehNear == null)
{
ehNear = eh;//第一个
ehNearB = GetBaseCount(ehtype, err.GetType());
}
else
{
if (eh.TryStart.Offset > ehNear.TryStart.Offset || eh.TryEnd.Offset < ehNear.TryEnd.Offset)//范围更小
{
ehNear = eh;
ehNearB = GetBaseCount(ehtype, err.GetType());
}
else if (eh.TryStart.Offset == ehNear.TryStart.Offset || eh.TryEnd.Offset == ehNear.TryEnd.Offset)//范围相等
{
if (ehtype == err.GetType())//类型一致,没有比这个更牛的了
{
ehNear = eh;
ehNearB = GetBaseCount(ehtype, err.GetType());
}
else if (GetType(ehNear.CatchType).TypeForSystem == err.GetType())//上次找到的就是第一,不用比了
{
continue;
}
else //比较上次找到的类型,和这次找到的类型的亲缘性;
{
int newehNearB = GetBaseCount(ehtype, err.GetType());
if (newehNearB == -1) continue;
if (newehNearB < ehNearB)
{
ehNear = eh;
ehNearB = newehNearB;
}
}
}
}
ehs.Add(eh);
}
}
}
}
if (ehNear != null)
{
frame.stackCalc.Push(err);
frame.SetCodePos(ehNear.HandlerStart.Offset);// ._pos = ehNear.HandlerStart;
RunCodeWithTry(body, frame);
return true;
}
return false;
}
示例2: ExecuteFunc
public object ExecuteFunc(IMethod_Sharp method, object _this, object[] _params)
{
_activeContext = this;
if (this.DebugLevel >= 9)
{
environment.logger.Log("<Call>::" + method.DeclaringType.FullName + "::" + method.Name.ToString());
}
StackFrame stack = new StackFrame(method.Name, method.isStatic);
stacks.Push(stack);
object[] _withp = null;
bool isctor = method.Name == ".ctor";
if (isctor)
{
//CLRSharp_Instance pthis = new CLRSharp_Instance(GetType(func.ReturnType) as Type_Common_CLRSharp);
//StackFrame.RefObj pthis = new StackFrame.RefObj(stack, 0, StackFrame.RefType.arg);
_withp = new object[_params == null ? 1 : (_params.Length + 1)];
if (_params != null)
_params.CopyTo(_withp, 1);
_withp[0] = _this;
}
else
{
if (!method.isStatic)
{
_withp = new object[(_params == null) ? 1 : (_params.Length + 1)];
_withp[0] = _this;
if (_params != null)
_params.CopyTo(_withp, 1);
}
else
{
_withp = _params;
}
}
stack.SetParams(_withp);
if (method.body != null)
{
stack.Init(method.body);
stack.SetCodePos(0);
//._pos = method.body.bodyNative.Instructions[0];
stack._codepos = 0;
if (method.body.bodyNative.HasExceptionHandlers && !SetNoTry)
{
RunCodeWithTry(method.body, stack);
}
else
{
RunCode(stack, method.body);
}
}
if (this.DebugLevel >= 9)
{
environment.logger.Log("<CallEnd>");
}
var ret = stacks.Pop().Return();
return isctor ? _this : ret;
//if (func.HasBody)
//{
// RunCode(stack, func.Body.Instructions);
//}
//var ret = stacks.Pop().Return();
//if (this.DebugLevel >= 9)
//{
// environment.logger.Log("<CallEnd>");
//}
//return ret;
}