本文整理汇总了C#中Type.GetMethods方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetMethods方法的具体用法?C# Type.GetMethods怎么用?C# Type.GetMethods使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.GetMethods方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: printType
static void printType( Type t, string filename ){
using( StreamWriter sw = new StreamWriter( filename ) ){
sw.WriteLine( "class " + t.Name + "{" );
// public instance methodを出力
sw.WriteLine( "public:" );
foreach( MethodInfo mi in t.GetMethods( BindingFlags.Instance | BindingFlags.Public ) ){
printMethod( mi, sw, " " );
}
sw.WriteLine();
// public static methodを出力
foreach( MethodInfo mi in t.GetMethods( BindingFlags.Static | BindingFlags.Public ) ){
printMethod( mi, sw, " static " );
}
sw.WriteLine();
// private instance methodを出力
sw.WriteLine( "private:" );
foreach( MethodInfo mi in t.GetMethods( BindingFlags.Instance | BindingFlags.NonPublic ) ){
printMethod( mi, sw, " " );
}
sw.WriteLine();
// private static methodを出力
foreach( MethodInfo mi in t.GetMethods( BindingFlags.Static | BindingFlags.NonPublic ) ){
printMethod( mi, sw, " static " );
}
sw.WriteLine();
sw.WriteLine( "};" );
}
}
示例2: ListMethods2
static void ListMethods2(Type t)
{
Console.WriteLine("**** Methods 2 *****");
var methodNames = from n in t.GetMethods() select n;
foreach (var name in methodNames) {
Console.WriteLine("->{0}", name);
}
}
示例3: GetTestMethods
public ICollection<System.Reflection.MethodInfo> GetTestMethods(Type type)
{
var c = new List<System.Reflection.MethodInfo>();
foreach (var method in type.GetMethods())
if (method.GetCustomAttributes(true)
.Where(w => w.ToString().Contains("Fact")).Count() > 0)
c.Add(method);
return c;
}
示例4: Initialize
protected void Initialize(Type controllerType)
{
ControllerType = controllerType;
var allMethods = ControllerType.GetMethods(BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public);
ActionMethods = Array.FindAll(allMethods, IsValidActionMethod);
// The attribute routing mapper will remove methods from this set as they are mapped.
// The lookup tables are initialized lazily to ensure that direct routing's changes are respected.
StandardRouteMethods = new HashSet<MethodInfo>(ActionMethods);
}
示例5: AddAll
public void AddAll(Type testCaseType)
{
foreach (MethodInfo method in testCaseType.GetMethods()) {
foreach (Attribute attribute in method.GetCustomAttributes(false)) {
if (attribute != null) {
ConstructorInfo constructor = testCaseType.GetConstructors () [0];
UUnitTestCase newTestCase = (UUnitTestCase)constructor.Invoke (null);
newTestCase.SetTest (method.Name);
Add (newTestCase);
}
}
}
}
示例6: ListTestMethods
private List<MethodInfo> ListTestMethods(Type type)
{
var allMethods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
var matching = new List<MethodInfo>();
foreach (var method in allMethods) {
var attrs = method.GetCustomAttributes(typeof(Test), false);
if (attrs == null || attrs.Length == 0) continue;
// Method matches, just check if it's not filtered out
if (ShouldExecuteTest(method.Name)) {
matching.Add(method);
}
}
return matching;
}
示例7: ListMethods3
static void ListMethods3(Type t)
{
Console.WriteLine("****** Methods 3 ******");
MethodInfo[] mi = t.GetMethods();
foreach (var m in mi) {
string retVal = m.ReturnType.FullName;
string paramInfo = "(";
foreach (ParameterInfo pi in m.GetParameters()) {
paramInfo += string.Format("{0} {1} ", pi.ParameterType, pi.Name);
}
paramInfo += ")";
Console.WriteLine("->{0} {1} {2}", retVal, m.Name, paramInfo);
}
}
示例8: EnumerateMethods
IEnumerable<MethodInfo> EnumerateMethods(Type type)
{
foreach (var m in type.GetMethods (flags)) {
// It is not really doable or at least very easy to support
// callbacks. So, ignore them so far.
if (IsCallType (m.ReturnType) || m.GetParameters ().Select (p => p.ParameterType).Any (t => IsCallType (t)))
continue;
// FIXME: in this type, there are complicated variable between object and call (Action/Func), so I disabled all members at all.
if (type.GetTypeReferenceName () == "AstWalkerDetailCallback")
continue;
yield return m;
}
}
示例9: AddAll
private void AddAll(Type testCaseType)
{
var methods = testCaseType.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
foreach (MethodInfo m in methods)
{
var attributes = m.GetCustomAttributes(typeof(UUnitTestAttribute), false);
if (attributes.Length > 0)
{
ConstructorInfo constructor = testCaseType.GetConstructors()[0];
UUnitTestCase newTestCase = (UUnitTestCase)constructor.Invoke(null);
newTestCase.SetTest(m.Name);
Add(newTestCase);
}
}
}
示例10: Calculate
public static long Calculate(Type t)
{
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms);
bw.Write(t.FullName);
bw.Write((int)t.Attributes);
foreach(FieldInfo fi in t.GetFields(BindingFlags.Public |
BindingFlags.NonPublic | BindingFlags.Instance).OrderBy(f => f.Name))
{
bw.Write(fi.Name);
bw.Write((int)fi.Attributes);
}
foreach(PropertyInfo pi in
t.GetProperties(BindingFlags.Public | BindingFlags.Instance).OrderBy(p
=> p.Name))
{
bw.Write(pi.Name);
bw.Write((int)pi.Attributes);
}
foreach(ConstructorInfo ci in
t.GetConstructors(BindingFlags.Public | BindingFlags.Instance).OrderBy(c
=> Signature(c.Name, c.GetParameters())))
{
bw.Write(Signature(ci.Name, ci.GetParameters()));
bw.Write((int)ci.Attributes);
}
foreach(MethodInfo mi in t.GetMethods(BindingFlags.Public |
BindingFlags.Instance | BindingFlags.Static).OrderBy(m =>
Signature(m.Name, m.GetParameters())))
{
bw.Write(Signature(mi.Name, mi.GetParameters()));
bw.Write((int)mi.Attributes);
}
bw.Close();
ms.Close();
byte[] b = ms.ToArray();
byte[] hash = sha.TransformFinalBlock(b, 0, b.Length);
return (((long)hash[0]) << 56) | (((long)hash[1]) << 48) |
(((long)hash[2]) << 40) | (((long)hash[3]) << 32)
| (((long)hash[4]) << 24) | (((long)hash[5]) << 16) |
(((long)hash[6]) << 8) | (((long)hash[7]) << 0);
}
示例11: RunTests
static void RunTests(int series, Type type)
{
const string Prefix = "Test";
MethodInfo createObjectMethod = type.GetMethod ("CreateObject");
foreach (MethodInfo mi in type.GetMethods ()) {
string name = mi.Name;
if (!name.StartsWith (Prefix))
continue;
int id = Convert.ToInt32 (name.Substring (Prefix.Length));
int res = test_method_thunk (series + id, mi.MethodHandle.Value, createObjectMethod.MethodHandle.Value);
if (res != 0) {
Console.WriteLine ("{0} returned {1}", mi, res);
Environment.Exit ((id << 3) + res);
}
}
}
示例12: getMethodsOfSignature
private static MethodInfo[] getMethodsOfSignature(Type from, Type returnType, Type[] parameterTypes)
{
List<MethodInfo> methods = new List<MethodInfo>();
foreach (MethodInfo mi in from.GetMethods())
{
if (mi.ReturnType == returnType)
{
ParameterInfo[] pi = mi.GetParameters();
if (pi.Length != parameterTypes.Length)
{
continue;
}
for (int i = 0; i < parameterTypes.Length; i++)
{
if (pi[i].ParameterType != parameterTypes[i])
{
continue;
}
}
methods.Add(mi);
}
}
return methods.ToArray();
}
示例13: AddTypeInfo
public static int AddTypeInfo(Type type, out ATypeInfo tiOut)
{
ATypeInfo ti = new ATypeInfo();
ti.fields = type.GetFields(JSMgr.BindingFlagsField);
ti.properties = type.GetProperties(JSMgr.BindingFlagsProperty);
ti.methods = type.GetMethods(JSMgr.BindingFlagsMethod);
ti.constructors = type.GetConstructors();
if (JSBindingSettings.NeedGenDefaultConstructor(type))
{
// null means it's default constructor
var l = new List<ConstructorInfo>();
l.Add(null);
l.AddRange(ti.constructors);
ti.constructors = l.ToArray();
}
ti.howmanyConstructors = ti.constructors.Length;
FilterTypeInfo(type, ti);
int slot = allTypeInfo.Count;
allTypeInfo.Add(ti);
tiOut = ti;
return slot;
}
示例14: GetAllMethods
static MethodInfo [] GetAllMethods (Type t)
{
BindingFlags static_flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly |BindingFlags.Static;
BindingFlags instance_flag = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly |BindingFlags.Instance;
MethodInfo [] static_members = t.GetMethods (static_flag);
MethodInfo [] instance_members = t.GetMethods (instance_flag);
if (static_members == null && instance_members == null)
return null;
MethodInfo [] all_members = new MethodInfo [static_members.Length + instance_members.Length];
static_members.CopyTo (all_members, 0); // copy all static members
instance_members.CopyTo (all_members, static_members.Length); // copy all instance members
return all_members;
}
示例15: RunTests
static public int RunTests(Type type, string[] args, TestDriverReporter reporter) {
int failed = 0, ran = 0;
int result, expected;
int i, j, iterations;
string name;
MethodInfo[] methods;
bool do_timings = false;
bool verbose = false;
bool quiet = false;
int tms = 0;
DateTime start, end = DateTime.Now;
iterations = 1;
var exclude = new Dictionary<string, string> ();
List<string> run_only = new List<string> ();
List<string> exclude_test = new List<string> ();
if (args != null && args.Length > 0) {
for (j = 0; j < args.Length;) {
if (args [j] == "--time") {
do_timings = !quiet;
j ++;
} else if (args [j] == "--iter") {
iterations = Int32.Parse (args [j + 1]);
j += 2;
} else if ((args [j] == "-v") || (args [j] == "--verbose")) {
verbose = !quiet;
j += 1;
} else if ((args [j] == "-q") || (args [j] == "--quiet")) {
quiet = true;
verbose = false;
do_timings = false;
j += 1;
} else if (args [j] == "--exclude") {
exclude [args [j + 1]] = args [j + 1];
j += 2;
} else if (args [j] == "--exclude-test") {
exclude_test.Add (args [j + 1]);
j += 2;
} else if (args [j] == "--run-only") {
run_only.Add (args [j + 1]);
j += 2;
} else {
Console.WriteLine ("Unknown argument: " + args [j]);
return 1;
}
}
}
int nskipped = 0;
methods = type.GetMethods (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Static);
for (int iter = 0; iter < iterations; ++iter) {
for (i = 0; i < methods.Length; ++i) {
name = methods [i].Name;
if (!name.StartsWith ("test_", StringComparison.Ordinal))
continue;
if (run_only.Count > 0) {
bool found = false;
for (j = 0; j < run_only.Count; j++) {
if (name.EndsWith (run_only [j])) {
found = true;
break;
}
}
if (!found)
continue;
}
if (exclude.Count > 0 || exclude_test.Count > 0) {
var attrs = methods [i].GetCustomAttributes (typeof (CategoryAttribute), false);
bool skip = false;
for (j = 0; j < exclude_test.Count; j++) {
if (name.EndsWith (exclude_test [j])) {
skip = true;
break;
}
}
foreach (CategoryAttribute attr in attrs) {
if (exclude.ContainsKey (attr.Category))
skip = true;
}
if (skip) {
if (verbose)
Console.WriteLine ("Skipping '{0}'.", name);
nskipped ++;
continue;
}
}
for (j = 5; j < name.Length; ++j)
if (!Char.IsDigit (name [j]))
break;
if (verbose)
Console.WriteLine ("Running '{0}' ...", name);
expected = Int32.Parse (name.Substring (5, j - 5));
start = DateTime.Now;
result = (int)methods [i].Invoke (null, null);
if (do_timings) {
end = DateTime.Now;
long tdiff = end.Ticks - start.Ticks;
int mdiff = (int)tdiff/10000;
tms += mdiff;
Console.WriteLine ("{0} took {1} ms", name, mdiff);
//.........这里部分代码省略.........