當前位置: 首頁>>代碼示例>>C#>>正文


C# TypeReference.CopyGeneric方法代碼示例

本文整理匯總了C#中Mono.Cecil.TypeReference.CopyGeneric方法的典型用法代碼示例。如果您正苦於以下問題:C# TypeReference.CopyGeneric方法的具體用法?C# TypeReference.CopyGeneric怎麽用?C# TypeReference.CopyGeneric使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.TypeReference的用法示例。


在下文中一共展示了TypeReference.CopyGeneric方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ImplementWait

        protected virtual IEnumerable<Instruction> ImplementWait(Instruction instruction, TypeReference waitFutureType)
        {
            //FIXME: We're reordering instructions to keep the stack balanced before/after continuation.
            // Better to save/restore the stack instead? ->
            //  Foo (MayThrow (), GetSomeFuture ().Wait ());
            // Normally, if MayThrow () throws an exception, GetSomeFuture () is not called. But because we're
            // reordering, GetSomeFuture *is* called, the future is waited, and then MayThrow throws on the continuation.

            //FIXME: Support multiple predecessors here!
            var lastStack = cfg.FindLastStackItem (block, instruction, IsBarrier).Single (); // this is the Future
            // these are the items on the stack before the Future. they will be moved til after the continuation
            var continuationInst = cfg.FindStackHeight (block, lastStack, 0, IsBarrier).Single ();

            IList<Instruction> precontinuationStack = null;
            if (continuationInst != lastStack) {
                precontinuationStack = ExtractInstructionRange (continuationInst, lastStack);

                // FIXME: Currently, we can't handle any jumps into this critical area
                if (precontinuationStack.Any (i => method.Body.IsJumpTarget (i)))
                    throw new NotSupportedException ("Support for jumps into continuation critical area not implemented");
            }

            // Insert ldarg.0 for CoroutineFuture.Chain
            // FIXME: Right now, we're depending on the C# compiler's behavior re. not separating arg0 from call
            InsertBefore (lastStack, Instruction.Create (OpCodes.Ldarg_0));

            var chainInstructions = new List<Instruction> ();
            chainInstructions.Add (Instruction.Create (OpCodes.Call, chain));

            var continuation = Instruction.Create (OpCodes.Ret);
            continuations.Add (continuation);

            var afterContinuation = Instruction.Create (OpCodes.Ldarg_0);

            // CoroutineFuture.Chain returns false if we don't need continuation
            chainInstructions.Add (Instruction.Create (OpCodes.Brfalse_S, afterContinuation));

            chainInstructions.Add (continuation);
            chainInstructions.Add (afterContinuation);

            // this is the instruction that will follow if the future is not faulted
            var notFaulted = Instruction.Create (OpCodes.Nop);

            // check for exceptions
            chainInstructions.Add (Instruction.Create (OpCodes.Call, checkException));
            chainInstructions.Add (Instruction.Create (OpCodes.Ldarg_0));
            chainInstructions.Add (Instruction.Create (OpCodes.Ldfld, chainedFld));
            chainInstructions.Add (Instruction.Create (OpCodes.Callvirt, module.Import (getException)));
            chainInstructions.Add (Instruction.Create (OpCodes.Brfalse, notFaulted));

            // mark exception as handled and throw it again right there
            chainInstructions.Add (Instruction.Create (OpCodes.Ldarg_0));
            chainInstructions.Add (Instruction.Create (OpCodes.Ldfld, chainedFld));
            chainInstructions.Add (Instruction.Create (OpCodes.Dup));
            chainInstructions.Add (Instruction.Create (OpCodes.Ldc_I4, -1));
            chainInstructions.Add (Instruction.Create (OpCodes.Call, module.Import (setStatus)));
            chainInstructions.Add (Instruction.Create (OpCodes.Callvirt, module.Import (getException)));
            chainInstructions.Add (Instruction.Create (OpCodes.Throw));

            // redirect jumps from our phony Wait call to the chain call.
            method.Body.Instructions.RedirectJumps (instruction, chainInstructions [0]);

            // -- add continuation to InstructionMap
            InstructionMap.Add (chainInstructions [0], chainInstructions);

            yield return notFaulted;

            // move anything on the stack before the Wait to after the continuation
            if (precontinuationStack != null) {
                foreach (var inst in precontinuationStack)
                    yield return inst;

            }

            // load the continuation result if there is one

            // FIXME: Eventually, we prolly don't want to do this if we're just going to pop the result..
            //   but we'd have to get rid of the pop instruction too...
            if (waitFutureType != null /* && instruction.Next.OpCode != OpCodes.Pop */) {
                var genWaitFuture = waitFutureType.CopyGeneric (coroutineType, skews);
                yield return Instruction.Create (OpCodes.Ldarg_0);
                yield return Instruction.Create (OpCodes.Ldfld, chainedFld);
                yield return Instruction.Create (OpCodes.Isinst, genWaitFuture);
                yield return Instruction.Create (OpCodes.Call, module.ImportFrom (getValue, genWaitFuture));
            }

            // reset chained to null
            yield return Instruction.Create (OpCodes.Ldarg_0);
            yield return Instruction.Create (OpCodes.Ldnull);
            yield return Instruction.Create (OpCodes.Stfld, chainedFld);
        }
開發者ID:chkn,項目名稱:cirrus,代碼行數:91,代碼來源:AsyncMethodTransform.cs

示例2: FixTypeToken

 // -----
 // We are taking a method implementation and extracting it into its own class.
 // If the method is generic, we need to make that class generic and update any
 // type refs to the old method's generic parameters to refer to the new class's
 // generic parameters instead.
 protected TypeReference FixTypeToken(TypeReference token)
 {
     return module.Import (token.CopyGeneric (coroutineType, skews));
 }
開發者ID:chkn,項目名稱:cirrus,代碼行數:9,代碼來源:AsyncMethodTransform.cs


注:本文中的Mono.Cecil.TypeReference.CopyGeneric方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。