11 Mayıs 2016 Çarşamba

MethodCallExpression Sınıfı

Arguments Alanı
Bu alan Metod çağrısına geçilen parametrelerdir. Şöyle yaparız.
var myList = new List<string> { "A" };
Expression<Func<string, bool>> a = (s) => myList.Contains(s);
ParseContainsExpression(a.Body as MethodCallExpression);

private bool ParseContainsExpression(MethodCallExpression expression)
{
    expression.Object; //myList
    expression.Arguments[0]; //s    
    return false;
}
Method Alanı
Bu alan MethodInfo tipindendir. Şöyle yapabiliriz.
MethodCallExpression e = ...;
// The method must be called Contains and must return bool
if (e.Method.Name != "Contains" || e.Method.ReturnType != typeof(bool)) 
  return false;
Object Alanı
Bu alan Object tipindendir. null ise static bir metod çağrılıyordur. Değilse bir nesnenin metodu çağrılıyordur. Çağrılan nesneyi belirtir. Şöyle yaparız.
var obj = e.Object;
if (obj == null){
  // Static method
  ...
}
else
{
  // Instance method
  ...
}

Hiç yorum yok:

Yorum Gönder