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


C# MethodBase.ToString方法代码示例

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


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

示例1: GetNumberOfStackPops

 public override int GetNumberOfStackPops(MethodBase aMethod)
 {
   switch (OpCode)
   {
     case Code.Initobj:
       return 1;
     case Code.Ldelema:
       return 2;
     case Code.Newarr:
       return 1;
     case Code.Box:
       return 1;
     case Code.Stelem:
       return 3;
     case Code.Ldelem:
       return 2;
     case Code.Isinst:
       return 1;
     case Code.Castclass:
       return 1;
     case Code.Constrained:
       return 0;
     case Code.Unbox_Any:
       return 1;
     case Code.Unbox:
       return 1;
     case Code.Stobj:
       return 2;
     case Code.Ldobj:
       return 1;
     default:
       throw new NotImplementedException("OpCode '" + OpCode + "' not implemented! Encountered in method " + aMethod.ToString());
   }
 }
开发者ID:bing2514,项目名称:Cosmos,代码行数:34,代码来源:OpType.cs

示例2: CreateMethod

        public static LateBoundMethod CreateMethod(MethodBase method)
        {
            DynamicMethod dynamicMethod = CreateDynamicMethod(method.ToString(), typeof(object), new[] { typeof(object), typeof(object[]) }, method.DeclaringType);
            ILGenerator generator = dynamicMethod.GetILGenerator();

            ParameterInfo[] args = method.GetParameters();

            Label argsOk = generator.DefineLabel();

            generator.Emit(OpCodes.Ldarg_1);
            generator.Emit(OpCodes.Ldlen);
            generator.Emit(OpCodes.Ldc_I4, args.Length);
            generator.Emit(OpCodes.Beq, argsOk);

            generator.Emit(OpCodes.Newobj, typeof(TargetParameterCountException).GetConstructor(Type.EmptyTypes));
            generator.Emit(OpCodes.Throw);

            generator.MarkLabel(argsOk);

            if (!method.IsConstructor && !method.IsStatic)
                generator.PushInstance(method.DeclaringType);

            for (int i = 0; i < args.Length; i++)
            {
                generator.Emit(OpCodes.Ldarg_1);
                generator.Emit(OpCodes.Ldc_I4, i);
                generator.Emit(OpCodes.Ldelem_Ref);

                generator.UnboxIfNeeded(args[i].ParameterType);
            }

            if (method.IsConstructor)
                generator.Emit(OpCodes.Newobj, (ConstructorInfo)method);
            else if (method.IsFinal || !method.IsVirtual)
                generator.CallMethod((MethodInfo)method);

            Type returnType = method.IsConstructor
              ? method.DeclaringType
              : ((MethodInfo)method).ReturnType;

            if (returnType != typeof(void))
                generator.BoxIfNeeded(returnType);
            else
                generator.Emit(OpCodes.Ldnull);

            generator.Return();

            return (LateBoundMethod)dynamicMethod.CreateDelegate(typeof(LateBoundMethod));
        }
开发者ID:Nangal,项目名称:Exceptionless,代码行数:49,代码来源:DelegateFactory.cs

示例3: fixDotNetSignature

        // calculate signature so that is is compatible with CORE
        public static String fixDotNetSignature(MethodBase mbMethodBase, String sReturnParameter)
        {
            try
            {
                // internal dotnet method that already has all paramters calculated
                //                String sMethodSignature = (String)reflection.invokeMethod_InstanceStaticPublicNonPublic(mbMethodBase, "ConstructName", new object[] { mbMethodBase });
                var sMethodSignature =
                    (String)
                    DI.reflection.invokeMethod_Static("System.Reflection.RuntimeMethodInfo", "ConstructName",
                                                      new object[] { mbMethodBase });
                if (sMethodSignature == null)
                {
                    DI.log.error("in fixDotNetSignature could not resolve method signature for :{0}",
                                 mbMethodBase.ToString());
                    sMethodSignature = "(COULD NOT RESOLVE SIGNATURE): " + mbMethodBase;
                }
                sMethodSignature = sMethodSignature.Replace(", ", ";");
                String sClass = mbMethodBase.ReflectedType.FullName;
                String sFullSignature = String.Format("{0}.{1}:{2}", sClass, sMethodSignature, sReturnParameter);

                // specific method fixes:                
                sFullSignature = sFullSignature.Replace("System.String", "string");
                sFullSignature = sFullSignature.Replace("System.Object", "object");
                sFullSignature = sFullSignature.Replace("Int16", "short");
                sFullSignature = sFullSignature.Replace("Int32", "int");
                sFullSignature = sFullSignature.Replace("Int64", "long");
                sFullSignature = sFullSignature.Replace("Boolean", "bool");
                sFullSignature = sFullSignature.Replace("Double", "double");
                sFullSignature = sFullSignature.Replace("Void", "void");
                sFullSignature = sFullSignature.Replace(" ByRef", "");
                // this doesn't seem to be included in the CIR signature                 

                return sFullSignature;
            }
            catch (Exception ex)
            {
                DI.log.error("In fixDotNetSignature:{0}", ex.Message);
                return "";
            }
        }
开发者ID:o2platform,项目名称:O2.Platform.Projects.Misc_and_Legacy,代码行数:41,代码来源:OunceLabsScannerHacks.cs

示例4: Matches

 public bool Matches(MethodBase member)
 {
     var interfacetypes = member.DeclaringType.GetInterfaces();
     foreach (var interfacetype in interfacetypes)
     {
         var method = interfacetype.GetMethod(member.Name);
         if (method.ToString() == member.ToString())
         {
             foreach (CachingAttribute attribute in ReflectionHelper.GetAllAttributes<CachingAttribute>(method, true))
             {
                 if (attribute.CachingEnable)
                     return true;
             }
         }
     }
     foreach (CachingAttribute attribute in ReflectionHelper.GetAllAttributes<CachingAttribute>(member, true))
     {
         if (attribute.CachingEnable)
             return true;
     }
     return false;
 }
开发者ID:dishiyicijinqiu,项目名称:OneCardAccess,代码行数:22,代码来源:CachingAttributeMatchingRule.cs

示例5: Disassemble

        public DisassembledMethod Disassemble(MethodBase method)
        {
            Contract.Requires(method != null);
            Contract.Requires(CanDisassemble(method));

            var methodBody = method.GetMethodBody();
            if (methodBody == null)
            {
                throw new NotSupportedException(method.DeclaringType +" {" +  method.ToString() + "} "+ method.GetMethodImplementationFlags() );
            }
            Contract.Assert(methodBody!=null);
            // ReSharper disable PossibleNullReferenceException
            var ilBytes = methodBody.GetILAsByteArray();
            // ReSharper restore PossibleNullReferenceException

            Type returnType = method is MethodInfo
                                  ? (method as MethodInfo).ReturnType
                                  : typeof (void);

            var handlingClauses = methodBody.ExceptionHandlingClauses;
            Type[] genericParameters = null;
            if (method.IsGenericMethod)
            {
                genericParameters = method.GetGenericArguments();
            }
            return new DisassembledMethod(
                ilBytes,
                Scan(ilBytes, handlingClauses),
                new ModuleMetadataResolver(method.Module),
                handlingClauses,
                methodBody.LocalVariables,
                returnType,
                method.GetParameters(),
                method.IsGenericMethodDefinition ,
                genericParameters );
        }
开发者ID:kazuk,项目名称:ProjectOosaki,代码行数:36,代码来源:Disassembler.cs

示例6: Format

 public static string Format(DateTime t, Object o, MethodBase m, String msg)
 {
     return "[" + t.ToString("HH:mm:ss") + "](" + o.GetHashCode() + "){ " + m.ToString() + " } >> " + msg;
 }
开发者ID:blstream,项目名称:Patronage2013-CaptureTheFlag,代码行数:4,代码来源:DebugInfo.cs

示例7: OkToUseBase

        /// <summary>
        /// TODO: Resolve IsPublic, IsNotPublic semantics of reflection
        /// </summary>
        /// <param name="ci"></param>
        /// <returns></returns>
        private bool OkToUseBase(MethodBase ci, out string message)
        {
            if (ci.IsAbstract)
            {
                message = "Will not use: method or constructor is abstract: " + ci.ToString();
                return false;
            }

            foreach (ParameterInfo pi in ci.GetParameters())
            {
                if (pi.ParameterType.Name.EndsWith("&"))
                {
                    message = "Will not use: method or constructor has a parameter containing \"&\": " + ci.ToString();
                    return false;
                }
                if (pi.IsOut)
                {
                    message = "Will not use: method or constructor has an out parameter: " + ci.ToString();
                    return false;
                }
                if (pi.ParameterType.IsGenericParameter)
                {
                    message = "Will not use: method or constructor has a generic parameter: " + ci.ToString();
                    return false;
                }
            }

            if (!this.useInternal && !ci.IsPublic)
            {
                message = "Will not use: method or constructor is not public: " + ci.ToString();
                return false;
            }

            if (ci.IsPrivate)
            {
                message = "Will not use: method or constructor is private: " + ci.ToString();
                return false;
            }

            if (ci.IsStatic)
            {
                if (!useStaticMethods)
                {
                    message = "Will not use: method or constructor is static: " + ci.ToString();
                    return false;
                }
            }

            if (ci.DeclaringType.Equals(typeof(object)))
            {
                message = "Will not use: method is System.Object's: " + ci.ToString();
                return false;
            }


            foreach (Attribute attr in ci.GetCustomAttributes(true))
            {

                if (attr is ObsoleteAttribute)
                {
                    //WriteLine("Obsolete Method " + ci.DeclaringType + "::" + ci.Name + "()" + "detected\n");
                    message = "Will not use: has attribute System.ObsoleteAttribute: " + ci.ToString();
                    return false;
                }
                //TODO: there are still cases where an obsolete method is not caught. e.g. System.Xml.XmlSchema::ElementType

            }

            message = "@@@OK8" + ci.ToString();
            return true;
        }
开发者ID:SJMakin,项目名称:Randoop.NET,代码行数:76,代码来源:ReflectionFilters.cs

示例8: Serialize

 /// <summary>
 /// Returns the method reference which refers specified method.
 /// </summary>
 /// <param name="method">The method to refer.</param>
 /// <returns>The method reference which refers specified method.</returns>
 public static MethodRef Serialize(MethodBase method)
 {
     return _reverseCache.GetValue(method)
         ?? new MethodRef(
                 TypeRef.Serialize(method.ReflectedType),
                 method.Name != ".ctor"
                     ? method.Name
                     : null,
                 method.ToString(),
                 method.IsGenericMethod && !method.IsGenericMethodDefinition
                     ? method.GetGenericArguments().SelectAll(TypeRef.Serialize)
                     : null
             ).Apply(m => _reverseCache.Add(method, m));
 }
开发者ID:takeshik,项目名称:yacq,代码行数:19,代码来源:MethodRef.cs

示例9: CompileTimeValidate

        /// <summary>
        /// Method called at compile-time by the weaver just before the instance is serialized.
        /// </summary>
        /// <param name="method">Method on which this instance is applied.</param>
        /// <remarks>
        /// <para>Derived classes should implement this method if they want to compute some information
        /// at compile time. This information to be stored in member variables. It shall be
        /// serialized at compile time and deserialized at runtime.
        /// </para>
        /// <para>
        /// You cannot store and serialize the <paramref name="method"/> parameter because it is basically
        /// a runtime object. You shall receive the <see cref="MethodBase"/> at runtime by the
        /// <see cref="RuntimeInitialize"/> function.
        /// </para>
        /// </remarks>
        public override bool CompileTimeValidate( MethodBase method )
        {
            bool hasError = false;

            // Cannot be a constructor.
            MethodInfo methodInfo = method as MethodInfo;
            if ( methodInfo == null )
            {
                DbInvokeMessageSource.Instance.Write( SeverityType.Error, "DBI0001",
                                                      new object[] {method.DeclaringType.FullName} );
                return false;
            }

            // Should have void return type.
            if ( methodInfo.ReturnType != typeof(void) )
            {
                DbInvokeMessageSource.Instance.Write( SeverityType.Error, "DBI0002",
                                                      new object[] {method.ToString()} );
                hasError = true;
            }

            // All parameters should be mappable.
            foreach ( ParameterInfo parameter in methodInfo.GetParameters() )
            {
                Type parameterType = parameter.ParameterType;
                if ( parameterType.IsByRef )
                    parameterType = parameterType.GetElementType();

                if ( DbTypeMapping.GetPreferredMapping( parameterType ) == null )
                {
                    DbInvokeMessageSource.Instance.Write( SeverityType.Error, "DBI0003",
                                                          new object[]
                                                              {
                                                                  method.ToString(), parameter.ParameterType.FullName,
                                                                  parameter.Name
                                                              } );
                    hasError = true;
                }
            }

            return !hasError;
        }
开发者ID:jogibear9988,项目名称:ormbattle,代码行数:57,代码来源:DbInvokeAttribute.cs

示例10: Warn

 public void Warn(string sText, MethodBase method = null)
 {
   Flush(LogLevel.WARN, method == null ? sText : method.ToString() + ":" + sText);
 }
开发者ID:gunivan,项目名称:log.net,代码行数:4,代码来源:Logger.cs

示例11: Rewrite

 public override bool Rewrite(CodeDescriptor decompilee, MethodBase callee, StackElement[] args, IDecompiler stack, IFunctionBuilder builder)
 {
     throw new ArgumentException("Method " + callee.ToString() + " was assumed not to be called at runtime. " +
         "However, a call to this method was found in " + decompilee.Method.ToString());
 }
开发者ID:venusdharan,项目名称:systemsharp,代码行数:5,代码来源:ComponentsAttributes.cs

示例12: Create

 public static MethodBodyInfo Create(MethodBase method)
 {
     MethodBodyInfo mbi = new MethodBodyInfo();
       mbi.Identity = method.GetHashCode();
       mbi.TypeName = method.GetType().Name;
       mbi.MethodToString = method.ToString();
       ReadableILStringVisitor readableIlStringVisitor = new ReadableILStringVisitor((IILStringCollector) new MethodBodyInfo.MethodBodyInfoBuilder(mbi), (IFormatProvider) DefaultFormatProvider.Instance);
       new ILReader(method).Accept((ILInstructionVisitor) readableIlStringVisitor);
       return mbi;
 }
开发者ID:jklipp,项目名称:codegravity,代码行数:10,代码来源:MethodBodyInfo.cs

示例13: Describe

 internal static string Describe(MethodBase methodBase)
 {
     return "{0} {1}{2} {3}".FormatInvariant(
         Describe(methodBase.ReflectedType),
         DescribeVisibility(methodBase),
         methodBase.IsStatic ? " static" : String.Empty,
         methodBase.ToString()
     );
 }
开发者ID:olivierdagenais,项目名称:testoriented,代码行数:9,代码来源:PublicInterfaceScanner.cs

示例14: GetId

 /// <summary>Gets the id for a method.</summary>
 /// <param name="methodBase">The method base.</param>
 /// <returns>A string unique to this method</returns>
 public static string GetId(MethodBase methodBase)
 {
     //return methodBase.GetHashCode().ToString();
     return methodBase.Module.Name + ">" + methodBase.DeclaringType.FullName + ">" + methodBase.ToString();
 }
开发者ID:stegru,项目名称:ExceptionExplorer,代码行数:8,代码来源:Method.cs

示例15: MethodData

				public MethodData (MethodBase mi, int il_size)
				{
					this.Type = mi.DeclaringType.ToString ();
					this.MethodName = mi.ToString ();
					this.MethodAttributes = (int) mi.Attributes;
					this.ILSize = il_size;
				}
开发者ID:jakesays,项目名称:mono,代码行数:7,代码来源:compiler-tester.cs


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