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


C# TypeInfo.GetMethods方法代码示例

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


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

示例1: GetPublicAndProtectedMethods

        private ClassInfo GetPublicAndProtectedMethods(TypeInfo type)
        {
            var methods = type.GetMethods(BindingFlags.Static | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
                .Where(o => o.IsFamily || o.IsPublic);

            var methodInfos = methods.ToArray();
            return new ClassInfo {Class = type, Methods = methodInfos};
        }
开发者ID:ajelesin,项目名称:test-66,代码行数:8,代码来源:Program.cs

示例2: GetCleanupMethod

        public static BenchmarkMethodMetadata GetCleanupMethod(TypeInfo classWithBenchmarks)
        {
            Contract.Requires(classWithBenchmarks != null);
            var cleanupMethods = classWithBenchmarks.GetMethods().Where(
               y => y.IsDefined(typeof(PerfCleanupAttribute), true)).ToList();
            if (!cleanupMethods.Any() || IsTypeInvalidForBenchmarks(classWithBenchmarks))
                return BenchmarkMethodMetadata.Empty;

            // Need to log and throw an error here for benchmarks that have multiple setups declared
            if (cleanupMethods.Count > 1)
            {
                var ex =
                    new NBenchException(
                        $"{classWithBenchmarks.Name} has a declared {cleanupMethods.Count} PerfCleanupAttributes. A maximum of 1 is allowed per class. Failing...");
                _reflectionOutput.Error(ex.Message);
                throw ex;
            }

            var matchingMethod = cleanupMethods.Single();

            var takesContext = MethodTakesBenchmarkContext(matchingMethod);
            return new BenchmarkMethodMetadata(matchingMethod, takesContext, false);
        }
开发者ID:ThomasBombadil,项目名称:NBench,代码行数:23,代码来源:ReflectionDiscovery.cs

示例3: addMethods

		private static void addMethods(TypeInfo type, CodeTypeReference typeRef, CodeFieldReferenceExpression this_underlyingObject,
			CodeTypeDeclaration wrap)
		{

			var methods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance & ~BindingFlags.SetProperty & ~BindingFlags.GetProperty).Where(x => x.Name != "GetType" && x.Name != "Equals" && x.Name != "ToString" && !x.Name.StartsWith("add_") && !x.Name.StartsWith("remove_"));
			foreach (var m in methods)
			{
				var method = new CodeMemberMethod();
				method.Attributes = MemberAttributes.Public ;
				if (!m.IsVirtual) method.Attributes |= MemberAttributes.Final;
				method.Name = m.Name;
				
				foreach (var p in m.GetParameters())
				{
					var param = new CodeParameterDeclarationExpression(new CodeTypeReference(p.ParameterType), p.Name);
					method.Parameters.Add(param);
				}
				var parameters = method.Parameters.Cast<CodeParameterDeclarationExpression>().Select(x => new CodeVariableReferenceExpression(x.Name)).ToArray();
				var call = new CodeMethodInvokeExpression(this_underlyingObject, m.Name, parameters);
				if (m.ReturnParameter.ParameterType != typeof(void))
				{
					var ret = new CodeMethodReturnStatement(call);
					method.ReturnType = new CodeTypeReference(m.ReturnParameter.ParameterType);
					method.Statements.Add(ret);
				}
				else
				{
					method.Statements.Add(call);
				}
				wrap.Members.Add(method);
			}
		}
开发者ID:OpenSharp,项目名称:UnitWrappers,代码行数:32,代码来源:InstanceWraperizer.cs

示例4: CreateBenchmarksForClass

        public static IReadOnlyList<BenchmarkClassMetadata> CreateBenchmarksForClass(TypeInfo classWithBenchmarks)
        {
            Contract.Requires(classWithBenchmarks != null);

            if(IsTypeInvalidForBenchmarks(classWithBenchmarks))
                return new List<BenchmarkClassMetadata>();

            var setupMethod = GetSetupMethod(classWithBenchmarks);
            var cleanupMethod = GetCleanupMethod(classWithBenchmarks);

            var allPerfMethods =
                classWithBenchmarks.GetMethods().Where(
                    MethodHasValidBenchmark).ToList();

            var benchmarks = new List<BenchmarkClassMetadata>(allPerfMethods.Count);
            foreach (var perfMethod in allPerfMethods)
            {
                var takesContext = MethodTakesBenchmarkContext(perfMethod);
                benchmarks.Add(new BenchmarkClassMetadata(classWithBenchmarks.AsType(), setupMethod,
                    new BenchmarkMethodMetadata(perfMethod, takesContext, false), cleanupMethod));
            }
            return benchmarks;
        }
开发者ID:ThomasBombadil,项目名称:NBench,代码行数:23,代码来源:ReflectionDiscovery.cs

示例5: GetHandlerActions

 public IEnumerable<MethodInfo> GetHandlerActions(TypeInfo handlerType)
 {
     List<MethodInfo> actions = handlerType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(IsHandlerAction).ToList();
     return actions;
 }
开发者ID:Ontropix,项目名称:CQRSalad,代码行数:5,代码来源:DefaultDispatcherHandlersProvider.cs


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