Questions tagged [methodbase]
17 questions
43
votes
7 answers
MoveNext instead of actual method/task name
Using log4net declared as:
private readonly ILog log =
LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType());
In an async method or task, like this one:
public async void CheckSomething()
{
log.Info(null);
…

user1307346
- 715
- 3
- 9
- 14
12
votes
2 answers
MethodBase.GetCurrentMethod() Performance?
I have written a log class and a function as in the following code:
Log(System.Reflection.MethodBase methodBase, string message)
Every time I log something I also log the class name from the methodBase.Name and methodBase.DeclaringType.Name.
I read…

Ioannis
- 2,985
- 4
- 25
- 19
11
votes
2 answers
How to read a method body with reflection
Is it possible to find out anything about a Method body with reflection?
How?

smartcaveman
- 41,281
- 29
- 127
- 212
8
votes
1 answer
How to get a MethodBase object for a method?
I am trying to work with the class found in this post but it needs a MethodBase to run.
I read What is the fastest way to get a MethodBase object? but i couldn't get any solution to work.
What i need to do is to get the MethodBase object from a…

Răzvan Flavius Panda
- 21,730
- 17
- 111
- 169
4
votes
2 answers
Check if the method uses PInvoke
Is there anyway to check if a method uses PInvoke ?
I'm looping through all the methods in an assembly using MethodBase but I want to check if the method is using PInvoke.
Here is the code I'm using :
foreach (MethodBase bases in…

method
- 1,369
- 3
- 16
- 29
3
votes
1 answer
Assign value to method parameter
Imagine a method with the following signature:
public void ExampleMethod(string id, object data,
ref object A, ref object B, ref object C)
{
//...
}
The value in data needs to be assigned to either A, B, C or nothing,…

David Rutten
- 4,716
- 6
- 43
- 72
3
votes
1 answer
In C# how can I evaluate if any members of a class contain switch case or if else constructs?
In C# how can I evaluate if any members of a class contain switch case or if else constructs? I want to check in a unit test if a class has been written with either switch...case or chained if....else.
I know how to get members of a class using…

Dib
- 2,001
- 2
- 29
- 45
3
votes
1 answer
Calling MethodBase's Invoke on a constructor (reflection)
First of all, sorry if this has been asked before. I've done a pretty comprehensive search and found nothing quite like it, but I may have missed something.
And now to the question: I'm trying to invoke a constructor through reflection, with no…

Alix
- 927
- 7
- 21
2
votes
1 answer
MethodBody.LocalVariables Count is confusing
For a simple Method with no local variables like the following
public static int Test1(short i, long j)
{
j = i + j;
switch (j)
{
case 1:
j = 2;
break;
default:
j = 11;
break;
}
return…

Paul Ash
- 21
- 2
2
votes
1 answer
MethodBase as Hashtable Key
I want to store some backing fields of Properties declared in derived classes in protected Hashtable contained in base class.
The usage of this mechanism in derived classes has to beas simple as possible.
So, can I use MethodBase.GetCurrentMethod()…

Szybki
- 1,083
- 14
- 29
2
votes
2 answers
How to Know Static Methods's Class Name
I have a class and it has some static methods. I have also another class inherits my first class like below;
public class Business
{
public static DataTable Get()
{
}
}
public class Model : Business
{
public int ID { get; set; }
…

thrashead
- 337
- 1
- 3
- 16
2
votes
2 answers
How to distinguish MethodBase in generics
I have a cache based on
Dictionary
The key is rendered from MethodBase.GetCurrentMethod. Everything worked fine until methods were explicitly declared. But one day it is appeared that:
Method1(string value)
Makes same entry…

Dewfy
- 23,277
- 13
- 73
- 121
1
vote
2 answers
Getting the MethodBase.GetCurrentMethod() but without Parameters
I have a function
public void AddPerson(string name)
{
Trace.WriteLine(MethodBase.GetCurrentMethod());
}
The expected output is
void AddPerson(string name)
But I wanted that the methodname outputted has no parameters in it.
void AddPerson()

JP Dolocanog
- 451
- 3
- 19
1
vote
2 answers
Cycle and access Method's parameters value
I have the following Method (I exemplify what I need in the comments of the method):
public static Dictionary Foo(bool os, bool rad, bool aci, bool outr, string distrito = null)
{
if (os == false && rad == false && aci == false && outr…

Dillinger
- 341
- 3
- 16
1
vote
1 answer
System.Reflection.MethodBase.GetCurrentMethod(); give ".ctor"
Stats: Visual Studio 2015 C#
Selenium Webdriver 2.53.1
Internet Explorer 11
Trying to add the Method Names to my reporting for clarity.
I am using
MethodBase m = System.Reflection.MethodBase.GetCurrentMethod();
I then call
…

Andy Williams
- 879
- 1
- 14
- 33