当前位置: 首页>>代码示例>>C#>>正文


C# TypeDef.GetBaseTypeThrow方法代码示例

本文整理汇总了C#中TypeDef.GetBaseTypeThrow方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDef.GetBaseTypeThrow方法的具体用法?C# TypeDef.GetBaseTypeThrow怎么用?C# TypeDef.GetBaseTypeThrow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TypeDef的用法示例。


在下文中一共展示了TypeDef.GetBaseTypeThrow方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConstructVTable

        public static VTable ConstructVTable(TypeDef typeDef, VTableStorage storage)
        {
            var ret = new VTable(typeDef);

            var slotDict = new Dictionary<VTableSignature, List<VTableSlot>>();

            // Partition II 12.2

            // Interfaces
            foreach (InterfaceImpl iface in typeDef.Interfaces) {
                VTable ifaceVTbl = storage.GetVTable(iface.Interface);
                if (ifaceVTbl != null)
                    ret.Inherit(ifaceVTbl, slotDict);
            }

            // Base type
            VTable baseVTbl = storage.GetVTable(typeDef.GetBaseTypeThrow());
            if (baseVTbl != null)
                ret.Inherit(baseVTbl, slotDict);

            List<MethodDef> virtualMethods = typeDef.Methods.Where(method => method.IsVirtual).ToList();
            var methodsProcessed = new HashSet<MethodDef>();

            // MethodImpls (Partition II 22.27)
            foreach (MethodDef method in virtualMethods)
                foreach (MethodOverride impl in method.Overrides) {
                    Debug.Assert(impl.MethodBody == method);

                    MethodDef targetMethod = impl.MethodDeclaration.ResolveThrow();
                    VTableSignature sig = VTableSignature.FromMethod(impl.MethodDeclaration);
                    Debug.Assert(slotDict.ContainsKey(sig));

                    var methodSlot = new VTableSlot(ret, method, method.DeclaringType.ToTypeSig(), VTableSignature.FromMethod(method));
                    ret.Override(slotDict, sig, methodSlot, targetMethod);
                    methodsProcessed.Add(method);
                }

            // Normal override
            foreach (MethodDef method in virtualMethods) {
                VTableSignature sig = VTableSignature.FromMethod(method);
                var methodSlot = new VTableSlot(ret, method, method.DeclaringType.ToTypeSig(), sig);
                if (slotDict.ContainsKey(sig) && slotDict[sig].Count > 0) {
                    ret.Override(slotDict, sig, methodSlot);
                    methodsProcessed.Add(method);
                }
            }

            // Remaining methods
            foreach (MethodDef method in typeDef.Methods.Where(method => method.IsVirtual).Except(methodsProcessed)) {
                var slot = new VTableSlot(ret, method, method.DeclaringType.ToTypeSig(), VTableSignature.FromMethod(method));
                if (method.IsFinal)
                    ret.Finals.Add(slot);
                else {
                    Debug.Assert(!ret.Slots.Any(s => s.MethodDef == method));
                    ret.Slots.Add(slot);
                }
            }

            return ret;
        }
开发者ID:2sic4you,项目名称:ConfuserEx,代码行数:60,代码来源:VTable.cs

示例2: ConstructVTable

        public static VTable ConstructVTable(TypeDef typeDef, VTableStorage storage)
        {
            var ret = new VTable(typeDef);

            var slotDict = new Dictionary<VTableSignature, List<VTableSlot>>();

            // Partition II 12.2

            // Interfaces
            foreach (InterfaceImpl iface in typeDef.Interfaces) {
                VTable ifaceVTbl = storage.GetVTable(iface.Interface);
                if (ifaceVTbl != null)
                    ret.Inherit(ifaceVTbl, slotDict);
            }

            // Base type
            VTable baseVTbl = storage.GetVTable(typeDef.GetBaseTypeThrow());
            if (baseVTbl != null)
                ret.Inherit(baseVTbl, slotDict);

            List<MethodDef> virtualMethods = typeDef.Methods.Where(method => method.IsVirtual).ToList();
            var methodsProcessed = new HashSet<MethodDef>();

            // MethodImpls (Partition II 22.27)
            foreach (MethodDef method in virtualMethods)
                foreach (MethodOverride impl in method.Overrides) {
                    Debug.Assert(impl.MethodBody == method);

                    MethodDef targetMethod = impl.MethodDeclaration.ResolveThrow();
                    VTableSignature sig = VTableSignature.FromMethod(impl.MethodDeclaration);
                    Debug.Assert(slotDict.ContainsKey(sig));

                    var methodSlot = new VTableSlot(ret, method, method.DeclaringType.ToTypeSig(), VTableSignature.FromMethod(method));
                    if (slotDict.ContainsKey(sig) && slotDict[sig].Count > 0) {
                        ret.Override(slotDict, sig, methodSlot, targetMethod);
                        methodsProcessed.Add(method);
                    }
                }

            // Normal override
            foreach (MethodDef method in virtualMethods) {
                VTableSignature sig = VTableSignature.FromMethod(method);
                var methodSlot = new VTableSlot(ret, method, method.DeclaringType.ToTypeSig(), sig);
                if (slotDict.ContainsKey(sig) && slotDict[sig].Count > 0) {
                    ret.Override(slotDict, sig, methodSlot);
                    methodsProcessed.Add(method);
                }
            }

            // Remaining methods
            foreach (MethodDef method in typeDef.Methods.Where(method => method.IsVirtual).Except(methodsProcessed)) {
                foreach (var remainingSlot in slotDict.Keys.Where(key => key.InterfaceType != null)) {
                    // If there is a remaining slot for an interface method which has the same name and signature as an unprocessed method,
                    // allow the method to override the slot.
                    // This is necessary because public methods which implement interface methods do not have an InterfaceType in their signature,
                    // but the keys of "slotDict" which were added for interface methods *do* have InterfaceType in their signature.  Therefore,
                    // these slots are not filled by the "Normal override" loop above.
                    if (new SigComparer().Equals(remainingSlot.MethodSig, method.MethodSig) && remainingSlot.Name.Equals(method.Name, StringComparison.Ordinal)) {
                        var methodSlot = new VTableSlot(ret, method, method.DeclaringType.ToTypeSig(), remainingSlot);
                        ret.Override(slotDict, remainingSlot, methodSlot);
                        methodsProcessed.Add(method);
                        goto next;
                    }
                }
                var slot = new VTableSlot(ret, method, method.DeclaringType.ToTypeSig(), VTableSignature.FromMethod(method));
                if (method.IsFinal)
                    ret.Finals.Add(slot);
                else {
                    Debug.Assert(!ret.Slots.Any(s => s.MethodDef == method));
                    ret.Slots.Add(slot);
                }
                next:
                continue;
            }

            return ret;
        }
开发者ID:GavinHwa,项目名称:ConfuserEx,代码行数:77,代码来源:VTable.cs


注:本文中的TypeDef.GetBaseTypeThrow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。