I am working on an ASP.NET MVC project and I am working on reflection.
I tried to determine whether a class does not have a standard, non-static public getter. I have devised the code below:
public static bool NotHavePublicGetter( Type deger, string propertyName)
{
try
{
if (deger == null)
throw new ArgumentNullException("Type");
if (string.IsNullOrEmpty(propertyName))
throw new ArgumentNullException(typeof(string).ToString());
PropertyInfo[] propertyInfoDizisi = deger.GetProperties(BindingFlags.Public | BindingFlags.Instance);
if (propertyInfoDizisi == null || !propertyInfoDizisi.Any())
throw new InvalidOperationException("propertyInfoDizisi == null || !propertyInfoDizisi.Any()");
MethodInfo getterMethodInfo = null;
StringBuilder getDotNetName = new StringBuilder();
getDotNetName.Append("get_");
getDotNetName.Append(propertyName);
foreach (PropertyInfo propertyInfo in propertyInfoDizisi)
{
if (propertyInfo == null)
continue;
getterMethodInfo = propertyInfo.GetGetMethod(false);
if (getterMethodInfo == null)
continue;
// At this point, I need to check CallingConvention property of getterMethodInfo
if (getDotNetName.ToString().Equals(getterMethodInfo.Name))
return false;
}
return true;
}
catch (ArgumentNullException hata)
{
//TODO productionda kalkacak.
//YAP2 testte aktive edilecek.
throw hata;
}
catch (InvalidOperationException hata)
{
//TODO productionda kalkacak.
//YAP2 testte aktive edilecek.
throw hata;
}
catch (Exception hata)
{
//TODO productionda kalkacak.
//YAP2 testte aktive edilecek.
throw hata;
}
//TODO productionda aktive gelecek.
//YAP2 testte deaktive edilecek.
//return true;
}
During debug, CallingConvention property of getterMethodInfo is “Standard | HasThis”. The problem here is that I cannot check getterMethodInfo property of “Standard | HasThis” . I tried “getterMethodInfo.CallingConvention == CallingConventions.Standard || getterMethodInfo.CallingConvention == CallingConventions.HasThis ” but it returns false.
How can I check at the point that CallingConvention property of getterMethodInfo is “Standard | HasThis”? Thanks in advance.