本文整理汇总了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};
}
示例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);
}
示例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);
}
}
示例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;
}
示例5: GetHandlerActions
public IEnumerable<MethodInfo> GetHandlerActions(TypeInfo handlerType)
{
List<MethodInfo> actions = handlerType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(IsHandlerAction).ToList();
return actions;
}