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

C# Reflection.MethodBase类代码示例

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

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



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

示例1: FormatMethod

 protected virtual string FormatMethod(MethodBase method)
 {
     var sb = new StringBuilder();
     if (method.DeclaringType != null)
     {
         sb.Append(method.DeclaringType.FullName);
         sb.Append(".");
     }
     sb.Append(method.Name);
     if (method.IsGenericMethod)
     {
         sb.Append("<");
         sb.Append(string.Join(", ", method.GetGenericArguments().Select(t => t.Name)));
         sb.Append(">");
     }
     sb.Append("(");
     var f = false;
     foreach (var p in method.GetParameters())
     {
         if (f) sb.Append(", ");
         else f = true;
         sb.Append(p.ParameterType.Name);
         sb.Append(' ');
         sb.Append(p.Name);
     }
     sb.Append(")");
     return sb.ToString();
 }
开发者ID:darilek,项目名称:dotvvm,代码行数:28,代码来源:ExceptionSectionFormatter.cs


示例2: Action

		public override object Action(object target, MethodBase method, object[] parameters, object result)
		{
			string namePrincipal = Thread.CurrentPrincipal.Identity.Name;
			if (namePrincipal == string.Empty)
			{
				namePrincipal = "Anonymous User";
			}

			namePrincipal = "User: " + namePrincipal;

			string text = "Assambly: " + target.ToString() + "\nMethod: " + method.Name;

			string content = Helper.ReadFile(_pathInternal);

			try
			{
				Helper.SaveToFile(namePrincipal, text, content, _pathInternal);
			}
			catch
			{
				throw;
			}

			return null;
		}
开发者ID:treytomes,项目名称:ILExperiments,代码行数:25,代码来源:LoggerToFile.cs


示例3: ReflectedMethod

 public ReflectedMethod(Identifier name, MethodBase method, Type targetType)
     : base(name, null, method, targetType)
 {
     DeclaringName = method.DeclaringType != targetType
         ? IdentifierFor.Method(method, method.DeclaringType)
         : name;
 }
开发者ID:cdrnet,项目名称:docu,代码行数:7,代码来源:ReflectedMethod.cs


示例4: MethodTracerItem

 /// <summary>
 /// Constructor.
 /// </summary>
 public MethodTracerItem(TypeEnum itemType, TracerItem.PriorityEnum priority, string message, MethodBase methodInfo, string threadName, string threadId)
     : base(itemType, priority, message)
 {
     _methodBase = methodInfo;
     _threadId = threadId;
     _threadName = threadName;
 }
开发者ID:redrhino,项目名称:DotNetConnectTerminal,代码行数:10,代码来源:MethodTracerItem.cs


示例5: CompileTimeValidate

        // Validate the attribute usage.
        public override bool CompileTimeValidate( MethodBase method )
        {
            // Don't apply to constructors.
            if ( method is ConstructorInfo )
            {
                Message.Write( SeverityType.Error, "CX0001", "Cannot cache constructors." );
                return false;
            }

            MethodInfo methodInfo = (MethodInfo) method;

            // Don't apply to void methods.
            if ( methodInfo.ReturnType.Name == "Void" )
            {
                Message.Write( SeverityType.Error, "CX0002", "Cannot cache void methods." );
                return false;
            }

            // Does not support out parameters.
            ParameterInfo[] parameters = method.GetParameters();
            for ( int i = 0; i < parameters.Length; i++ )
            {
                if ( parameters[i].IsOut )
                {
                    Message.Write( SeverityType.Error, "CX0003", "Cannot cache methods with return values." );
                    return false;
                }
            }

            return true;
        }
开发者ID:jogibear9988,项目名称:ormbattle,代码行数:32,代码来源:CacheAttribute.cs


示例6: IsStatic

		//===========================================================================================
		private bool IsStatic(MethodBase[] methods)
		{
			if (methods.Length != 1)
				return false;

			return IsStatic(methods[0]);
		}
开发者ID:dlemstra,项目名称:GraphicsMagick.NET,代码行数:8,代码来源:ExecuteCodeGenerator.cs


示例7: InitialiseProperties

        public void InitialiseProperties(
            Type classUnderTest,
            object instanceUnderTest,
            MethodBase methodUnderTest,
            object[] parameters,
            string nullParameter,
            int nullIndex,
            IExecutionSetup executionSetup)
        {
            // Act
            var sut = new MethodData(
                classUnderTest,
                instanceUnderTest,
                methodUnderTest,
                parameters,
                nullParameter,
                nullIndex,
                executionSetup);

            // Assert
            Assert.Same(classUnderTest, sut.ClassUnderTest);
            Assert.Equal(instanceUnderTest, sut.InstanceUnderTest);
            Assert.Same(methodUnderTest, sut.MethodUnderTest);
            Assert.Same(parameters, sut.Parameters);
            Assert.Same(nullParameter, sut.NullParameter);
            Assert.Equal(nullIndex, sut.NullIndex);
            Assert.Same(executionSetup, sut.ExecutionSetup);
        }
开发者ID:AutoTestNET,项目名称:AutoTest.ArgumentNullException,代码行数:28,代码来源:MethodDataShould.cs


示例8: MonoMethodMessage

		public MonoMethodMessage (MethodBase method, object [] out_args)
		{
			if (method != null)
				InitMessage ((MonoMethod)method, out_args);
			else
				args = null;
		}
开发者ID:jack-pappas,项目名称:mono,代码行数:7,代码来源:MonoMethodMessage.cs


示例9: GetNumberOfStackPushes

 public override int GetNumberOfStackPushes(MethodBase aMethod)
 {
   switch (OpCode)
   {
     case Code.Initobj:
       return 0;
     case Code.Ldelema:
       return 1;
     case Code.Newarr:
       return 1;
     case Code.Box:
       return 1;
     case Code.Stelem:
       return 0;
     case Code.Ldelem:
       return 1;
     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 0;
     case Code.Ldobj:
       return 1;
     default:
       throw new NotImplementedException("OpCode '" + OpCode + "' not implemented!");
   }
 }
开发者ID:bing2514,项目名称:Cosmos,代码行数:34,代码来源:OpType.cs


示例10: TypeActivationContext

 /// <summary>
 /// Initializes a new instance of the MethodActivationContext class.
 /// </summary>
 /// <param name="target">The object instance that initiated the activation request.</param>
 /// <param name="targetMethod">The method where the activation was invoked.</param>
 /// <param name="concreteType">The type to be constructed.</param>
 /// <param name="additionalArguments">The additional arguments that will be passed to the constructor.</param>
 public TypeActivationContext(object target, MethodBase targetMethod,
     Type concreteType, object[] additionalArguments)
     : base(concreteType, additionalArguments)
 {
     Target = target;
     TargetMethod = targetMethod;
 }
开发者ID:slieser,项目名称:LinFu,代码行数:14,代码来源:TypeActivationContext.cs


示例11: FromMethod

 /// <summary>
 /// Creates a REST call from a given method.
 /// If the method has no marker, a null is returned
 /// </summary>
 /// <param name="methodBase">The method base.</param>
 /// <returns></returns>
 public static RestCall FromMethod(MethodBase methodBase)
 {
     var httpGet = methodBase.GetCustomAttribute<HttpGetAttribute>();
     if (httpGet != null)
         return new RestCall("GET", httpGet.UriTemplate);
     return null;
 }
开发者ID:systemmetaphor,项目名称:BlueDwarf,代码行数:13,代码来源:RestCall.cs


示例12: Action

		public override object Action(object target, MethodBase method, object[] parameters, object result)
		{
			string namePrincipal = Thread.CurrentPrincipal.Identity.Name;
			if (namePrincipal == string.Empty)
			{
				namePrincipal = "Anonymous User";
			}

			namePrincipal = "User: " + namePrincipal;

			string text = new StringBuilder()
				.AppendFormat("Assambly: {0}", target).AppendLine()
				.AppendFormat("Method: {0}", method.Name).AppendLine().AppendLine()
				.AppendFormat("InnerException: {0}" + (result as Exception).InnerException)
				.ToString();

			string content = Helper.ReadFile(_pathInternal);

			try
			{
				Helper.SaveToFile(namePrincipal, text, content, _pathInternal);
			}
			catch
			{
				throw;
			}

			return null;
		}
开发者ID:treytomes,项目名称:ILExperiments,代码行数:29,代码来源:LogExceptionToFile.cs


示例13: CreateLocalsForByRefParams

 protected byte CreateLocalsForByRefParams(byte paramArrayIndex, MethodBase invocationInfo)
 {
     byte numberOfByRefParams = 0;
     ParameterInfo[] parameters = invocationInfo.GetParameters();
     for (int i = 0; i < ParameterTypes.Length; i++)
     {
         Type paramType = ParameterTypes[i];
         if (paramType.IsByRef)
         {
             Type type = paramType.GetElementType();
             Emit.DeclareLocal(type);
             if (!parameters[i].IsOut) // no initialization necessary is 'out' parameter
             {
                 Emit.ldarg(paramArrayIndex)
                     .ldc_i4(i)
                     .ldelem_ref
                     .CastFromObject(type)
                     .stloc(numberOfByRefParams)
                     .end();
             }
             numberOfByRefParams++;
         }
     }
     return numberOfByRefParams;
 }
开发者ID:ByteSempai,项目名称:Ubiquitous,代码行数:25,代码来源:InvocationEmitter.cs


示例14: ExceptionThrowingTest

 public ExceptionThrowingTest(TimeSpan runningTime, MethodBase method, Exception thrownException, IObjectInstance instance = null,
                              IEnumerable<IObjectInstance> arguments = null)
     : base(runningTime, method, instance, arguments)
 {
     if (thrownException == null) throw new ArgumentNullException("thrownException");
     Exception = thrownException;
 }
开发者ID:eneiand,项目名称:Baseline,代码行数:7,代码来源:ExceptionThrowingTest.cs


示例15: Method

 internal Method(MethodBase methodBase, UtilityFactory factory)
 {
     if (methodBase == null)
         throw new ArgumentNullException("methodBase");
     this.methodBase = methodBase;
     this.factory = factory;
 }
开发者ID:Stewartarmbrecht,项目名称:xBDD,代码行数:7,代码来源:Method.cs


示例16: RunTest

        private static TestResult RunTest(object instance, MethodBase method)
        {
            var result = new TestResult { Name = method.Name };

            var sw = new Stopwatch();
            sw.Start();
            try
            {
                method.Invoke(instance, null);
                result.WasSuccessful = true;
            }
            catch (Exception ex)
            {
                result.WasSuccessful = false;
                result.Message = ex.ToString();
            }
            finally
            {
                sw.Stop();

                result.Duration = sw.ElapsedMilliseconds;
            }

            return result;
        }
开发者ID:hbidadi,项目名称:UnitTestsForDiagnosticsEndpoints,代码行数:25,代码来源:DiagnosticsController.cs


示例17: GetMethodBaseSignaturePrefix

        private static string GetMethodBaseSignaturePrefix(MethodBase methodBase)
        {
            var stringBuilder = new StringBuilder();

            if (methodBase.IsPrivate)
            {
                stringBuilder.Append("private ");
            }
            else if (methodBase.IsPublic)
            {
                stringBuilder.Append("public ");
            }
            if (methodBase.IsAbstract)
            {
                stringBuilder.Append("abstract ");
            }
            if (methodBase.IsStatic)
            {
                stringBuilder.Append("static ");
            }
            if (methodBase.IsVirtual)
            {
                stringBuilder.Append("virtual ");
            }

            return stringBuilder.ToString();
        }
开发者ID:JaysonJG,项目名称:Catel,代码行数:27,代码来源:MemberInfoExtensions.cs


示例18: AssertMethodRule

// ReSharper disable UnusedParameter.Local
        private void AssertMethodRule(Func<string, Type, IRegexFilter> addMethod, MethodBase method, Type type, bool expectedInclude)
        {
            IRegexFilter actualFilter = addMethod(method.Name, type);

            int expectedRules = 1;
            if (expectedInclude && type != null) expectedRules++;

            Assert.Same(addMethod.Target, actualFilter);
            Assert.Equal(expectedRules, actualFilter.Rules.Count);
            RegexRule addedRule = actualFilter.MethodRules.Single();
            Assert.Equal(expectedInclude, addedRule.Include);
            Assert.NotNull(addedRule.Method);
            Assert.True(addedRule.MatchMethod(type ?? GetType(), method));
            Assert.Null(addedRule.Parameter);

            if (type == null)
            {
                Assert.Null(addedRule.Type);
            }
            else
            {
                Assert.NotNull(addedRule.Type);
                Assert.True(addedRule.MatchType(type));
            }
        }
开发者ID:AutoTestNET,项目名称:AutoTest.ArgumentNullException,代码行数:26,代码来源:RegexFilterExtensionsShould.cs


示例19: Invoke

		// Messages will be intercepted here and redirected
		// to another object.
		public override IMessage Invoke (IMessage msg)
		{
			try {
				if (msg is IConstructionCallMessage) {
					IActivator remActivator = (IActivator) RemotingServices.Connect (typeof (IActivator), "tcp://localhost:1234/RemoteActivationService.rem");
					IConstructionReturnMessage crm = remActivator.Activate ((IConstructionCallMessage) msg);
					return crm;
				} else {
					methodOverloaded = RemotingServices.IsMethodOverloaded ((IMethodMessage) msg);

					_mthBase = RemotingServices.GetMethodBaseFromMethodMessage ((IMethodMessage) msg);
					MethodCallMessageWrapper mcm = new MethodCallMessageWrapper ((IMethodCallMessage) msg);
					mcm.Uri = RemotingServices.GetObjectUri ((MarshalByRefObject) target);
					MarshalByRefObject objRem = (MarshalByRefObject) Activator.CreateInstance (GetProxiedType ());
					RemotingServices.ExecuteMessage ((MarshalByRefObject) objRem, (IMethodCallMessage) msg);
					IMessage rtnMsg = null;

					try {
						rtnMsg = _sink.SyncProcessMessage (msg);
					} catch (Exception e) {
						Console.WriteLine (e.Message);
					}

					Console.WriteLine ("RR:" + rtnMsg);
					return rtnMsg;
				}
			} catch (Exception ex) {
				Console.WriteLine (ex);
				return null;
			}
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:33,代码来源:RemotingServicesTest.cs


示例20: DynamicStackFrame

 public DynamicStackFrame(CodeContext context, MethodBase method, string funcName, string filename, int line) {
     _context = context;
     _funcName = funcName;
     _filename = filename;
     _lineNo = line;
     _method = method;
 }
开发者ID:joshholmes,项目名称:ironruby,代码行数:7,代码来源:DynamicStackFrame.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Reflection.MethodInfo类代码示例发布时间:2022-05-26
下一篇:
C# Reflection.MetadataToken类代码示例发布时间: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