• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# TypeSystem.MethodSignature类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: EmitIL

        public static MethodIL EmitIL(MethodDesc target)
        {
            Debug.Assert(target.Name == "Call");
            Debug.Assert(target.Signature.Length > 0
                && target.Signature[0] == target.Context.GetWellKnownType(WellKnownType.IntPtr));

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

            // Load all the arguments except the first one (IntPtr address)
            for (int i = 1; i < target.Signature.Length; i++)
            {
                codeStream.EmitLdArg(i);
            }

            // now load IntPtr address
            codeStream.EmitLdArg(0);

            // Create a signature for the calli by copying the signature of the containing method
            // while skipping the first argument
            MethodSignature template = target.Signature;
            TypeDesc returnType = template.ReturnType;
            TypeDesc[] parameters = new TypeDesc[template.Length - 1];
            for (int i = 1; i < template.Length; i++)
            {
                parameters[i - 1] = template[i];
            }

            var signature = new MethodSignature(template.Flags, 0, returnType, parameters);

            codeStream.Emit(ILOpcode.calli, emitter.NewToken(signature));
            codeStream.Emit(ILOpcode.ret);

            return emitter.Link();
        }
开发者ID:noahfalk,项目名称:corert,代码行数:35,代码来源:CalliIntrinsic.cs


示例2: TestMethodLookup

        public void TestMethodLookup()
        {
            MetadataType t = _testModule.GetType("GenericTypes", "GenericClass`1").MakeInstantiatedType(_context.GetWellKnownType(WellKnownType.Int32));

            MethodSignature sig = new MethodSignature(MethodSignatureFlags.None, 0, t.Instantiation[0], new TypeDesc[0] { });
            MethodDesc fooMethod = t.GetMethod("Foo", sig);
            Assert.NotNull(fooMethod);
        }
开发者ID:nguerrera,项目名称:corert,代码行数:8,代码来源:GenericTypeAndMethodTests.cs


示例3: InitializeSignature

        private MethodSignature InitializeSignature()
        {
            var metadataReader = MetadataReader;
            BlobReader signatureReader = metadataReader.GetBlobReader(metadataReader.GetMethodDefinition(_handle).Signature);

            EcmaSignatureParser parser = new EcmaSignatureParser(Module, signatureReader);
            var signature = parser.ParseMethodSignature();
            return (_signature = signature);
        }
开发者ID:niemyjski,项目名称:corert,代码行数:9,代码来源:EcmaMethod.cs


示例4: GetKnownMethod

        /// <summary>
        /// Retrieves a method on <paramref name="type"/> that is well known to the compiler.
        /// Throws an exception if the method doesn't exist.
        /// </summary>
        public static MethodDesc GetKnownMethod(this TypeDesc type, string name, MethodSignature signature)
        {
            MethodDesc method = type.GetMethod(name, signature);
            if (method == null)
            {
                throw new InvalidOperationException(String.Format("Expected method '{0}' not found on type '{1}'", name, type));
            }

            return method;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:14,代码来源:HelperExtensions.cs


示例5: EmitIL

        public static MethodIL EmitIL(MethodDesc target)
        {
            Debug.Assert(target.Name == "Call");
            Debug.Assert(target.Signature.Length > 0
                && target.Signature[0] == target.Context.GetWellKnownType(WellKnownType.IntPtr));

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

            // Load all the arguments except the first one (IntPtr address)
            for (int i = 1; i < target.Signature.Length; i++)
            {
                codeStream.EmitLdArg(i);
            }

            // now load IntPtr address
            codeStream.EmitLdArg(0);

            // Create a signature for the calli by copying the signature of the containing method
            // while skipping the first argument
            MethodSignature template = target.Signature;
            TypeDesc returnType = template.ReturnType;
            TypeDesc[] parameters = new TypeDesc[template.Length - 1];
            for (int i = 1; i < template.Length; i++)
            {
                parameters[i - 1] = template[i];
            }

            var signature = new MethodSignature(template.Flags, 0, returnType, parameters);

            bool useTransformedCalli = true;

            if ((signature.Flags & MethodSignatureFlags.UnmanagedCallingConventionMask) != 0)
            {
                // Fat function pointer only ever exist for managed targets.
                useTransformedCalli = false;
            }

            if (((MetadataType)target.OwningType).Name == "RawCalliHelper")
            {
                // RawCalliHelper doesn't need the transform.
                useTransformedCalli = false;
            }

            if (useTransformedCalli)
                EmitTransformedCalli(emitter, codeStream, signature);
            else
                codeStream.Emit(ILOpcode.calli, emitter.NewToken(signature));
            
            codeStream.Emit(ILOpcode.ret);

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


示例6: TestVirtualDispatchOnGenericType

        public void TestVirtualDispatchOnGenericType()
        {
            // Verifies that virtual dispatch to a non-generic method on a generic instantiation works
            DefType objectType = _context.GetWellKnownType(WellKnownType.Object);
            MethodSignature toStringSig = new MethodSignature(MethodSignatureFlags.None, 0, _stringType, Array.Empty<TypeDesc>());
            MethodDesc objectToString = objectType.GetMethod("ToString", toStringSig);
            Assert.NotNull(objectToString);
            MetadataType openTestType = _testModule.GetType("VirtualFunctionOverride", "SimpleGeneric`1");
            InstantiatedType testInstance = openTestType.MakeInstantiatedType(new Instantiation(new TypeDesc[] { objectType }));
            MethodDesc targetOnInstance = testInstance.GetMethod("ToString", toStringSig);

            MethodDesc targetMethod = VirtualFunctionResolution.FindVirtualFunctionTargetMethodOnObjectType(objectToString, testInstance);
            Assert.Equal(targetOnInstance, targetMethod);        
        }
开发者ID:huamichaelchen,项目名称:corert,代码行数:14,代码来源:VirtualFunctionOverrideTests.cs


示例7: GetStringInitializer

        /// <summary>
        /// NEWOBJ operation on String type is actually a call to a static method that returns a String
        /// instance (i.e. there's an explicit call to the runtime allocator from the static method body).
        /// This method returns the alloc+init helper corresponding to a given string constructor.
        /// </summary>
        public static MethodDesc GetStringInitializer(this MethodDesc constructorMethod)
        {
            Debug.Assert(constructorMethod.IsConstructor);
            Debug.Assert(constructorMethod.OwningType.IsString);

            var constructorSignature = constructorMethod.Signature;

            // There's an extra (useless) Object as the first arg to match RyuJIT expectations.
            var parameters = new TypeDesc[constructorSignature.Length + 1];
            parameters[0] = constructorMethod.Context.GetWellKnownType(WellKnownType.Object);
            for (int i = 0; i < constructorSignature.Length; i++)
                parameters[i + 1] = constructorSignature[i];

            MethodSignature sig = new MethodSignature(
                MethodSignatureFlags.Static, 0, constructorMethod.OwningType, parameters);

            MethodDesc result = constructorMethod.OwningType.GetKnownMethod("Ctor", sig);
            return result;
        }
开发者ID:huamichaelchen,项目名称:corert,代码行数:24,代码来源:HelperExtensions.cs


示例8: EmitIL

        public static MethodIL EmitIL(MethodDesc target)
        {
            Debug.Assert(target.Name == "CompareExchange" || target.Name == "Exchange");

            //
            // Find non-generic method to forward the generic method to.
            //

            int parameterCount = target.Signature.Length;
            Debug.Assert(parameterCount == 3 || parameterCount == 2);

            var objectType = target.Context.GetWellKnownType(WellKnownType.Object);

            var parameters = new TypeDesc[parameterCount];
            parameters[0] = objectType.MakeByRefType();
            for (int i = 1; i < parameters.Length; i++)
                parameters[i] = objectType;

            MethodSignature nonGenericSignature = new MethodSignature(MethodSignatureFlags.Static, 0, objectType, parameters);

            MethodDesc nonGenericMethod = target.OwningType.GetMethod(target.Name, nonGenericSignature);

            // TODO: Better exception type. Should be: "CoreLib doesn't have a required thing in it".
            if (nonGenericMethod == null)
                throw new NotImplementedException();

            //
            // Emit the forwarder
            //

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

            // Reload all arguments
            for (int i = 0; i < parameterCount; i++)
                codeStream.EmitLdArg(i);

            codeStream.Emit(ILOpcode.call, emitter.NewToken(nonGenericMethod));
            codeStream.Emit(ILOpcode.ret);

            return emitter.Link();
        }
开发者ID:noahfalk,项目名称:corert,代码行数:42,代码来源:InterlockedIntrinsic.cs


示例9: TestStandaloneSignatureGeneration

        public void TestStandaloneSignatureGeneration()
        {
            var transformResult = MetadataTransform.Run(new SingleFileMetadataPolicy(), new[] { _systemModule });

            var stringRecord = transformResult.GetTransformedTypeDefinition(
                (Cts.MetadataType)_context.GetWellKnownType(Cts.WellKnownType.String));
            var singleRecord = transformResult.GetTransformedTypeDefinition(
                (Cts.MetadataType)_context.GetWellKnownType(Cts.WellKnownType.Single));

            var sig = new Cts.MethodSignature(
                0, 0, _context.GetWellKnownType(Cts.WellKnownType.String),
                new[] { _context.GetWellKnownType(Cts.WellKnownType.Single) });

            var sigRecord = transformResult.Transform.HandleMethodSignature(sig);

            // Verify the signature is connected to the existing transformResult world
            Assert.Same(stringRecord, sigRecord.ReturnType.Type);
            Assert.Equal(1, sigRecord.Parameters.Count);
            Assert.Same(singleRecord, sigRecord.Parameters[0].Type);
        }
开发者ID:nguerrera,项目名称:corert,代码行数:20,代码来源:SimpleTests.cs


示例10: GetStringInitializer

        /// <summary>
        /// NEWOBJ operation on String type is actually a call to a static method that returs a String
        /// instance (i.e. there's an explict call to the runtime allocator from the static method body).
        /// This method returns the alloc+init helper corresponding to a given string constructor.
        /// </summary>
        public static MethodDesc GetStringInitializer(MethodDesc constructorMethod)
        {
            Debug.Assert(constructorMethod.IsConstructor);
            Debug.Assert(constructorMethod.OwningType.IsString);

            // There's an extra (useless) Object as the first arg to match RyuJIT expectations.
            var parameters = new TypeDesc[constructorMethod.Signature.Length + 1];
            parameters[0] = constructorMethod.Context.GetWellKnownType(WellKnownType.Object);
            for (int i = 0; i < constructorMethod.Signature.Length; i++)
                parameters[i + 1] = constructorMethod.Signature[i];

            MethodSignature sig = new MethodSignature(
                MethodSignatureFlags.Static, 0, constructorMethod.OwningType, parameters);

            MethodDesc result = constructorMethod.OwningType.GetMethod("Ctor", sig);

            // TODO: Better exception type. Should be: "CoreLib doesn't have a required thing in it".
            if (result == null)
                throw new NotImplementedException();

            return result;
        }
开发者ID:niemyjski,项目名称:corert,代码行数:27,代码来源:IntrinsicMethods.cs


示例11: Equals

        public bool Equals(MethodSignature otherSignature)
        {
            // TODO: Generics, etc.
            if (this._flags != otherSignature._flags)
                return false;

            if (this._genericParameterCount != otherSignature._genericParameterCount)
                return false;

            if (this._returnType != otherSignature._returnType)
                return false;

            if (this._parameters.Length != otherSignature._parameters.Length)
                return false;

            for (int i = 0; i < this._parameters.Length; i++)
            {
                if (this._parameters[i] != otherSignature._parameters[i])
                    return false;
            }

            return true;
        }
开发者ID:niemyjski,项目名称:corert,代码行数:23,代码来源:MethodDesc.cs


示例12: EmitIL

        public static MethodIL EmitIL(MethodDesc method)
        {
            if (!RequiresMarshalling(method))
                return null;

            try
            {
                return new PInvokeMarshallingILEmitter(method).EmitIL();
            }
            catch (NotSupportedException)
            {
                ILEmitter emitter = new ILEmitter();
                string message = "Method '" + method.ToString() +
                    "' requires non-trivial marshalling that is not yet supported by this compiler.";

                TypeSystemContext context = method.Context;
                MethodSignature ctorSignature = new MethodSignature(0, 0, context.GetWellKnownType(WellKnownType.Void),
                    new TypeDesc[] { context.GetWellKnownType(WellKnownType.String) });
                MethodDesc exceptionCtor = method.Context.GetWellKnownType(WellKnownType.Exception).GetKnownMethod(".ctor", ctorSignature);

                ILCodeStream codeStream = emitter.NewCodeStream();
                codeStream.Emit(ILOpcode.ldstr, emitter.NewToken(message));
                codeStream.Emit(ILOpcode.newobj, emitter.NewToken(exceptionCtor));
                codeStream.Emit(ILOpcode.throw_);
                codeStream.Emit(ILOpcode.ret);

                return emitter.Link();
            }
        }
开发者ID:schellap,项目名称:corert,代码行数:29,代码来源:PInvokeMarshallingILEmitter.cs


示例13: AppendCppMethodDeclaration

        public void AppendCppMethodDeclaration(CppGenerationBuffer sb, MethodDesc method, bool implementation, string externalMethodName = null, MethodSignature methodSignature = null)
        {
            if (methodSignature == null)
                methodSignature = method.Signature;

            if (externalMethodName != null)
            {
                sb.Append("extern \"C\" ");
            }
            else
            {
                if (!implementation)
                {
                    sb.Append("static ");
                }
            }
            sb.Append(GetCppSignatureTypeName(methodSignature.ReturnType));
            sb.Append(" ");
            if (externalMethodName != null)
            {
                sb.Append(externalMethodName);
            }
            else
            {
                if (implementation)
                {
                    sb.Append(GetCppMethodDeclarationName(method.OwningType, GetCppMethodName(method)));
                }
                else
                {
                    sb.Append(GetCppMethodName(method));
                }
            }
            sb.Append("(");
            bool hasThis = !methodSignature.IsStatic;
            int argCount = methodSignature.Length;
            if (hasThis)
                argCount++;

            List<string> parameterNames = null;
            if (method != null)
            {
                IEnumerable<string> parameters = GetParameterNamesForMethod(method);
                if (parameters != null)
                {
                    parameterNames = new List<string>(parameters);
                    if (parameterNames.Count != 0)
                    {
                        System.Diagnostics.Debug.Assert(parameterNames.Count == argCount);
                    }
                    else
                    {
                        parameterNames = null;
                    }
                }
            }

            for (int i = 0; i < argCount; i++)
            {
                if (hasThis)
                {
                    if (i == 0)
                    {
                        var thisType = method.OwningType;
                        if (thisType.IsValueType)
                            thisType = thisType.MakeByRefType();
                        sb.Append(GetCppSignatureTypeName(thisType));
                    }
                    else
                    {
                        sb.Append(GetCppSignatureTypeName(methodSignature[i - 1]));
                    }
                }
                else
                {
                    sb.Append(GetCppSignatureTypeName(methodSignature[i]));
                }
                if (implementation)
                {
                    sb.Append(" ");

                    if (parameterNames != null)
                    {
                        sb.Append(SanitizeCppVarName(parameterNames[i]));
                    }
                    else
                    {
                        sb.Append("_a");
                        sb.Append(i.ToStringInvariant());
                    }
                }
                if (i != argCount - 1)
                    sb.Append(", ");
            }
            sb.Append(")");
            if (!implementation)
                sb.Append(";");
        }
开发者ID:justinvp,项目名称:corert,代码行数:98,代码来源:CppWriter.cs


示例14: GetMethod

 /// <summary>
 /// Gets a named method on the type. This method only looks at methods defined
 /// in type's metadata. The <paramref name="signature"/> parameter can be null.
 /// If signature is not specified and there are multiple matches, the first one
 /// is returned. Returns null if method not found.
 /// </summary>
 // TODO: Substitutions, generics, modopts, ...
 public virtual MethodDesc GetMethod(string name, MethodSignature signature)
 {
     foreach (var method in GetMethods())
     {
         if (method.Name == name)
         {
             if (signature == null || signature.Equals(method.Signature))
                 return method;
         }
     }
     return null;
 }
开发者ID:mjp41,项目名称:corert,代码行数:19,代码来源:TypeDesc.cs


示例15: MethodSignatureBuilder

        public MethodSignatureBuilder(MethodSignature template)
        {
            _template = template;

            _flags = template._flags;
            _genericParameterCount = template._genericParameterCount;
            _returnType = template._returnType;
            _parameters = template._parameters;
        }
开发者ID:shahid-pk,项目名称:corert,代码行数:9,代码来源:MethodDesc.cs


示例16: ToSignature

        public MethodSignature ToSignature()
        {
            if (_template == null ||
                _flags != _template._flags ||
                _genericParameterCount != _template._genericParameterCount ||
                _returnType != _template._returnType ||
                _parameters != _template._parameters)
            {
                _template = new MethodSignature(_flags, _genericParameterCount, _returnType, _parameters);
            }

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


示例17: AppendSignaturePrefix

        private void AppendSignaturePrefix(StringBuilder sb, MethodSignature signature)
        {
            if (!signature.IsStatic)
                sb.Append("instance ");

            this.TypeNameFormatter.AppendNameWithValueClassPrefix(sb, signature.ReturnType);
        }
开发者ID:tijoytom,项目名称:corert,代码行数:7,代码来源:ILDisassember.cs


示例18: NewToken

 public ILToken NewToken(MethodSignature value)
 {
     return NewToken(value, 0x11000000);
 }
开发者ID:nguerrera,项目名称:corert,代码行数:4,代码来源:ILEmitter.cs


示例19: AppendSignatureArgumentList

        private void AppendSignatureArgumentList(StringBuilder sb, MethodSignature signature)
        {
            for (int i = 0; i < signature.Length; i++)
            {
                if (i != 0)
                    sb.Append(", ");

                this.TypeNameFormatter.AppendNameWithValueClassPrefix(sb, signature[i]);
            }
        }
开发者ID:tijoytom,项目名称:corert,代码行数:10,代码来源:ILDisassember.cs


示例20: PassCallArguments

 private void PassCallArguments(MethodSignature methodSignature, TypeDesc thisArgument)
 {
     int signatureLength = methodSignature.Length;
     int argumentsCount = (thisArgument != null) ? (signatureLength + 1) : signatureLength;
     int startingIndex = _stack.Top - argumentsCount;
     for (int i = 0; i < argumentsCount; i++)
     {
         var op = _stack[startingIndex + i];
         int argIndex = signatureLength - (argumentsCount - i);
         TypeDesc argType;
         if (argIndex == -1)
         {
             argType = thisArgument;
         }
         else
         {
             argType = methodSignature[argIndex];
         }
         AppendCastIfNecessary(argType, op);
         Append(op);
         if (i + 1 != argumentsCount)
             Append(", ");
     }
     _stack.PopN(argumentsCount);
 }
开发者ID:nguerrera,项目名称:corert,代码行数:25,代码来源:ILToCppImporter.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TypeSystem.TypeDesc类代码示例发布时间:2022-05-26
下一篇:
C# TypeSystem.MethodDesc类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap