var property = obj.GetType().GetProperty(blockName);
if (property == null)
{
var method = obj.GetType().GetMethod(blockName);
if (method == null)
return "[" + blockName + "]";
else
return method.Invoke(obj, null).ToString();
}
else
return property.GetValue(obj, null).ToString();
This code should look for a property named blockName
's value. If the property found, it should return its value. If not, it should look for function named blockName
's value. If it finds, it should call it and return the returned value. If it dosen't find the method, it should return [blockName's value
].
It's working great, but I'm looking for ways to make it more efficient. I don't want to convert methods to properties or properties to methods, because in the future I'll add parameters too. Can you help me please?
Thanks.