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


C# TypeSystem.MethodDesc类代码示例

本文整理汇总了C#中Internal.TypeSystem.MethodDesc的典型用法代码示例。如果您正苦于以下问题:C# MethodDesc类的具体用法?C# MethodDesc怎么用?C# MethodDesc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MethodDesc类属于Internal.TypeSystem命名空间,在下文中一共展示了MethodDesc类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindMethodOnTypeWithMatchingTypicalMethod

        /// <summary>
        /// Returns method as defined on a non-generic base class or on a base
        /// instantiation.
        /// For example, If Foo&lt;T&gt; : Bar&lt;T&gt; and overrides method M,
        /// if method is Bar&lt;string&gt;.M(), then this returns Bar&lt;T&gt;.M()
        /// but if Foo : Bar&lt;string&gt;, then this returns Bar&lt;string&gt;.M()
        /// </summary>
        /// <param name="typeExamine">A potentially derived type</param>
        /// <param name="method">A base class's virtual method</param>
        static public MethodDesc FindMethodOnTypeWithMatchingTypicalMethod(this TypeDesc targetType, MethodDesc method)
        {
            // If method is nongeneric and on a nongeneric type, then it is the matching method
            if (!method.HasInstantiation && !method.OwningType.HasInstantiation)
            {
                return method;
            }

            // Since method is an instantiation that may or may not be the same as typeExamine's hierarchy,
            // find a matching base class on an open type and then work from the instantiation in typeExamine's
            // hierarchy
            TypeDesc typicalTypeOfTargetMethod = method.GetTypicalMethodDefinition().OwningType;
            TypeDesc targetOrBase = targetType;
            do
            {
                TypeDesc openTargetOrBase = targetOrBase;
                if (openTargetOrBase is InstantiatedType)
                {
                    openTargetOrBase = openTargetOrBase.GetTypeDefinition();
                }
                if (openTargetOrBase == typicalTypeOfTargetMethod)
                {
                    // Found an open match. Now find an equivalent method on the original target typeOrBase
                    MethodDesc matchingMethod = targetOrBase.FindMethodOnExactTypeWithMatchingTypicalMethod(method);
                    return matchingMethod;
                }
                targetOrBase = targetOrBase.BaseType;
            } while (targetOrBase != null);

            Debug.Assert(false, "method has no related type in the type hierarchy of type");
            return null;
        }
开发者ID:schellap,项目名称:corert,代码行数:41,代码来源:TypeSystemHelpers.cs

示例2: IsMethodInCompilationGroup

        public override bool IsMethodInCompilationGroup(MethodDesc method)
        {
            if (method.GetTypicalMethodDefinition().ContainsGenericVariables)
                return true;

            return IsTypeInCompilationGroup(method.OwningType);
        }
开发者ID:schellap,项目名称:corert,代码行数:7,代码来源:MultiFileCompilationModuleGroup.cs

示例3: TryGetPregeneratedPInvoke

        /// <summary>
        /// Returns pregenerated interop code for given PInvoke method if one exist
        /// </summary>
        public static MethodDesc TryGetPregeneratedPInvoke(MethodDesc method)
        {
            Debug.Assert(method.IsPInvoke);

            var metadataType = (MetadataType)method.OwningType;
            var module = metadataType.Module;

            var assemblyName = ((IAssemblyDesc)module).GetName();

            var interopAssemblyName = new AssemblyName();

            interopAssemblyName.Name = assemblyName.Name + AssemblyNameSuffix;
            interopAssemblyName.Version = assemblyName.Version;
            interopAssemblyName.SetPublicKeyToken(interopAssemblyName.GetPublicKeyToken());
            interopAssemblyName.CultureName = assemblyName.CultureName;
            interopAssemblyName.ContentType = assemblyName.ContentType;

            var interopModule = module.Context.ResolveAssembly(interopAssemblyName, false);
            if (interopModule == null)
                return null;

            var pregeneratedMethod = GetMatchingMethod(interopModule, method);
            if (pregeneratedMethod == null)
            {
                // TODO: Better error message
                throw new MissingMemberException("Missing method in " + interopAssemblyName.Name + ":" + method.ToString());
            }
            return pregeneratedMethod;
        }
开发者ID:pootow,项目名称:corert,代码行数:32,代码来源:McgInteropSupport.cs

示例4: GetMatchingMethod

 // Returns null if no matching method is found
 private static MethodDesc GetMatchingMethod(ModuleDesc module, MethodDesc method)
 {
     var matchingType = GetMatchingType(module, method.OwningType);
     if (matchingType == null)
         return null;
     return matchingType.GetMethod(method.Name, method.Signature);
 }
开发者ID:pootow,项目名称:corert,代码行数:8,代码来源:McgInteropSupport.cs

示例5: EmitIL

        public static MethodIL EmitIL(MethodDesc target)
        {
            Debug.Assert(target.Name == "EETypePtrOf");
            Debug.Assert(target.Signature.Length == 0
                && target.Signature.ReturnType == target.OwningType);
            Debug.Assert(target.Instantiation.Length == 1);

            ILEmitter emitter = new ILEmitter();
            var codeStream = emitter.NewCodeStream();

            TypeSystemContext context = target.Context;
            TypeDesc runtimeTypeHandleType = context.GetWellKnownType(WellKnownType.RuntimeTypeHandle);
            MethodDesc getValueInternalMethod = runtimeTypeHandleType.GetKnownMethod("GetValueInternal", null);
            MethodDesc eetypePtrCtorMethod = context.SystemModule
                .GetKnownType("System", "EETypePtr")
                .GetKnownMethod(".ctor", new MethodSignature(0, 0, context.GetWellKnownType(WellKnownType.Void),
                new TypeDesc[] { context.GetWellKnownType(WellKnownType.IntPtr) }));

            // The sequence of these instructions is important. JIT is able to optimize out
            // the LDTOKEN+GetValueInternal call into "load EEType pointer onto the evaluation stack".
            codeStream.Emit(ILOpcode.ldtoken, emitter.NewToken(context.GetSignatureVariable(0, true)));
            codeStream.Emit(ILOpcode.call, emitter.NewToken(getValueInternalMethod));
            codeStream.Emit(ILOpcode.newobj, emitter.NewToken(eetypePtrCtorMethod));
            codeStream.Emit(ILOpcode.ret);

            return emitter.Link(target);
        }
开发者ID:tijoytom,项目名称:corert,代码行数:27,代码来源:EETypePtrOfIntrinsic.cs

示例6: FixupCellMetadataResolver

 public FixupCellMetadataResolver(NativeFormatMetadataUnit metadataUnit, MethodDesc methodContext)
 {
     _metadataUnit = metadataUnit;
     _methodContext = methodContext;
     _typeContext = methodContext.OwningType;
     _loadContextFromNativeLayout = null;
 }
开发者ID:nattress,项目名称:corert,代码行数:7,代码来源:FixupCellMetadataResolver.cs

示例7: FatFunctionPointerNode

        public FatFunctionPointerNode(MethodDesc methodRepresented)
        {
            // We should not create these for methods that don't have a canonical method body
            Debug.Assert(methodRepresented.GetCanonMethodTarget(CanonicalFormKind.Specific) != methodRepresented);

            Method = methodRepresented;
        }
开发者ID:nattress,项目名称:corert,代码行数:7,代码来源:FatFunctionPointerNode.cs

示例8: IsStubRequired

        /// <summary>
        /// Returns true if <paramref name="method"/> requires a stub to be generated.
        /// </summary>
        public static bool IsStubRequired(MethodDesc method)
        {
            Debug.Assert(method.IsPInvoke);

            // TODO: true if there are any custom marshalling rules on the parameters
            // TODO: true if SetLastError is true

            TypeDesc returnType = method.Signature.ReturnType;
            if (!IsBlittableType(returnType) && !returnType.IsVoid)
                return true;

            for (int i = 0; i < method.Signature.Length; i++)
            {
                if (!IsBlittableType(method.Signature[i]))
                {
                    return true;
                }
            }

            if (UseLazyResolution(method, method.GetPInvokeMethodMetadata().Module))
            {
                return true;
            }

            return false;
        }
开发者ID:shahid-pk,项目名称:corert,代码行数:29,代码来源:PInvokeILEmitter.cs

示例9: AppendMethodSignature

        private void AppendMethodSignature(StringBuilder sb, MethodDesc method)
        {
            // If this is an instantiated generic method, the formatted signature should
            // be uninstantiated (e.g. "void Foo::Bar<int>(!!0 param)", not "void Foo::Bar<int>(int param)")
            MethodSignature signature = method.GetMethodDefinition().Signature;

            AppendSignaturePrefix(sb, signature);
            sb.Append(' ');
            AppendOwningType(sb, method.OwningType);
            sb.Append("::");
            sb.Append(method.Name);

            if (method.HasInstantiation)
            {
                sb.Append('<');

                for (int i = 0; i < method.Instantiation.Length; i++)
                {
                    if (i != 0)
                        sb.Append(", ");
                    _typeNameFormatter.AppendNameWithValueClassPrefix(sb, method.Instantiation[i]);
                }

                sb.Append('>');
            }

            sb.Append('(');
            AppendSignatureArgumentList(sb, signature);
            sb.Append(')');
        }
开发者ID:tijoytom,项目名称:corert,代码行数:30,代码来源:ILDisassember.cs

示例10: DelegateInfo

        public DelegateInfo(Compilation compilation, MethodDesc target)
        {
            this.Target = target;

            var systemDelegate = compilation.TypeSystemContext.GetWellKnownType(WellKnownType.MulticastDelegate).BaseType;

            // TODO: delegates on virtuals
            if (target.IsVirtual && !target.IsFinal)
                throw new NotImplementedException("Delegate to virtual");

            // TODO: Delegates on valuetypes
            if (target.OwningType.IsValueType)
                throw new NotImplementedException("Delegate to valuetype");

            if (target.Signature.IsStatic)
            {
                this.ShuffleThunk = new DelegateShuffleThunk(target);

                this.Ctor = systemDelegate.GetKnownMethod("InitializeClosedStaticThunk", null);
            }
            else
            {
                this.Ctor = systemDelegate.GetKnownMethod("InitializeClosedInstance", null);
            }
        }
开发者ID:huamichaelchen,项目名称:corert,代码行数:25,代码来源:DelegateInfo.cs

示例11: GetVirtualMethodSlot

        /// <summary>
        /// Given a virtual method decl, return its VTable slot if the method is used on its containing type.
        /// Return -1 if the virtual method is not used.
        /// </summary>
        public static int GetVirtualMethodSlot(NodeFactory factory, MethodDesc method)
        {
            // TODO: More efficient lookup of the slot
            TypeDesc owningType = method.OwningType;
            int baseSlots = 0;
            var baseType = owningType.BaseType;

            while (baseType != null)
            {
                List<MethodDesc> baseVirtualSlots;
                factory.VirtualSlots.TryGetValue(baseType, out baseVirtualSlots);

                if (baseVirtualSlots != null)
                    baseSlots += baseVirtualSlots.Count;
                baseType = baseType.BaseType;
            }

            List<MethodDesc> virtualSlots = factory.VirtualSlots[owningType];
            int methodSlot = -1;
            for (int slot = 0; slot < virtualSlots.Count; slot++)
            {
                if (virtualSlots[slot] == method)
                {
                    methodSlot = slot;
                    break;
                }
            }
            
            return methodSlot == -1 ? -1 : baseSlots + methodSlot;
        }
开发者ID:noahfalk,项目名称:corert,代码行数:34,代码来源:VirtualMethodCallHelper.cs

示例12: Create

        /// <summary>
        /// Constructs a new instance of <see cref="DelegateCreationInfo"/> set up to construct a delegate of type
        /// '<paramref name="delegateType"/>' pointing to '<paramref name="targetMethod"/>'.
        /// </summary>
        public static DelegateCreationInfo Create(TypeDesc delegateType, MethodDesc targetMethod, NodeFactory factory)
        {
            var context = (CompilerTypeSystemContext)delegateType.Context;
            var systemDelegate = targetMethod.Context.GetWellKnownType(WellKnownType.MulticastDelegate).BaseType;

            int paramCountTargetMethod = targetMethod.Signature.Length;
            if (!targetMethod.Signature.IsStatic)
            {
                paramCountTargetMethod++;
            }

            DelegateInfo delegateInfo = context.GetDelegateInfo(delegateType.GetTypeDefinition());
            int paramCountDelegateClosed = delegateInfo.Signature.Length + 1;
            bool closed = false;
            if (paramCountDelegateClosed == paramCountTargetMethod)
            {
                closed = true;
            }
            else
            {
                Debug.Assert(paramCountDelegateClosed == paramCountTargetMethod + 1);
            }

            if (targetMethod.Signature.IsStatic)
            {
                MethodDesc invokeThunk;
                if (!closed)
                {
                    // Open delegate to a static method
                    invokeThunk = delegateInfo.Thunks[DelegateThunkKind.OpenStaticThunk];
                }
                else
                {
                    // Closed delegate to a static method (i.e. delegate to an extension method that locks the first parameter)
                    invokeThunk = delegateInfo.Thunks[DelegateThunkKind.ClosedStaticThunk];
                }

                var instantiatedDelegateType = delegateType as InstantiatedType;
                if (instantiatedDelegateType != null)
                    invokeThunk = context.GetMethodForInstantiatedType(invokeThunk, instantiatedDelegateType);

                // We use InitializeClosedStaticThunk for both because RyuJIT generates same code for both,
                // but passes null as the first parameter for the open one.
                return new DelegateCreationInfo(
                    factory.MethodEntrypoint(systemDelegate.GetKnownMethod("InitializeClosedStaticThunk", null)),
                    factory.MethodEntrypoint(targetMethod),
                    factory.MethodEntrypoint(invokeThunk));
            }
            else
            {
                if (!closed)
                    throw new NotImplementedException("Open instance delegates");

                bool useUnboxingStub = targetMethod.OwningType.IsValueType;

                return new DelegateCreationInfo(
                    factory.MethodEntrypoint(systemDelegate.GetKnownMethod("InitializeClosedInstance", null)),
                    factory.MethodEntrypoint(targetMethod, useUnboxingStub));
            }
        }
开发者ID:nguerrera,项目名称:corert,代码行数:64,代码来源:DelegateCreationInfo.cs

示例13: ContainsMethod

        public sealed override bool ContainsMethod(MethodDesc method)
        {
            if (method.HasInstantiation)
                return true;

            return ContainsType(method.OwningType);
        }
开发者ID:justinvp,项目名称:corert,代码行数:7,代码来源:MultiFileCompilationModuleGroup.cs

示例14: GetMethodIL

        public MethodIL GetMethodIL(MethodDesc method)
        {
            if (method is EcmaMethod)
            {
                // TODO: Workaround: we should special case methods with Intrinsic attribute, but since
                //       CoreLib source is still not in the repo, we have to work with what we have, which is
                //       an MCG attribute on the type itself...
                if (((MetadataType)method.OwningType).HasCustomAttribute("System.Runtime.InteropServices", "McgIntrinsicsAttribute"))
                {
                    if (method.Name == "Call")
                    {
                        return CalliIntrinsic.EmitIL(method);
                    }
                }

                if (method.IsIntrinsic)
                {
                    MethodIL result = TryGetIntrinsicMethodIL(method);
                    if (result != null)
                        return result;
                }

                if (method.IsPInvoke)
                {
                    return PInvokeMarshallingILEmitter.EmitIL(method);
                }

                return EcmaMethodIL.Create((EcmaMethod)method);
            }
            else
            if (method is MethodForInstantiatedType)
            {
                var methodDefinitionIL = GetMethodIL(method.GetTypicalMethodDefinition());
                if (methodDefinitionIL == null)
                    return null;
                return new InstantiatedMethodIL(methodDefinitionIL, method.OwningType.Instantiation, new Instantiation());
            }
            else
            if (method is InstantiatedMethod)
            {
                var methodDefinitionIL = GetMethodIL(method.GetMethodDefinition());
                if (methodDefinitionIL == null)
                    return null;
                return new InstantiatedMethodIL(methodDefinitionIL, new Instantiation(), method.Instantiation);
            }
            else
            if (method is ILStubMethod)
            {
                return ((ILStubMethod)method).EmitIL();
            }
            else
            if (method is ArrayMethod)
            {
                return ArrayMethodILEmitter.EmitIL((ArrayMethod)method);
            }
            else
            {
                return null;
            }
        }
开发者ID:smartmaster,项目名称:corert,代码行数:60,代码来源:ILProvider.cs

示例15: InitializeMethods

        private void InitializeMethods()
        {
            int numCtors;

            if (IsSzArray)
            {
                numCtors = 1;

                var t = this.ElementType;
                while (t.IsSzArray)
                {
                    t = ((ArrayType)t).ElementType;
                    numCtors++;
                }
            }
            else
            {
                // ELEMENT_TYPE_ARRAY has two ctor functions, one with and one without lower bounds
                numCtors = 2;
            }

            MethodDesc[] methods = new MethodDesc[(int)ArrayMethodKind.Ctor + numCtors];

            for (int i = 0; i < methods.Length; i++)
                methods[i] = new ArrayMethod(this, (ArrayMethodKind)i);

            Interlocked.CompareExchange(ref _methods, methods, null);
        }
开发者ID:morganbr,项目名称:corert,代码行数:28,代码来源:ArrayType.cs


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