Silverlight Reflection | GetCurrentMethod with passed parameters
I want to print the current method call (incl. return value) to the Visual Studio Output like this:
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
Func<object, object> ret = (value) =>
{
#if DEBUG
var debug = new StringBuilder();
debug.Append("MyConverter.Convert([");
debug.Append(values.Sum(v => (v != null ? v.ToString() : "null") + ',', null, v => v != null ? v.ToString() : "null"));
debug.Append("], " + targetType.ToString() + ", " + parameter.ToString() + ", " + culture.DisplayName + ") =" + value.ToString() + ";");
Debug.WriteLine(debug.ToString());
#endif
return value;
};
// [..]
}
I'm using this sometimes to achieve more informations (e.g. from a Converter as shown here) while debugging. However, that开发者_开发问答's just a roundabout way.
Is there any way to do it more flexible? Something like GetCurrentArguments (from MethodInfo)?
Since you are using it for debugging there is an option using the StackTrace and StackFrame To get the current method name, but you wont get the arguments, and there is a severe performance penalty.
精彩评论