You can't peek into a delegate like that;
This is not entirely true.
This is
completely ill-advised, but if you're okay with constraining the delegates to certain forms, you can pick through their bodies and re-write them on the fly using Expression Trees:
[source lang="csharp"]using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Linq.Expressions;namespace ModifyDelegateInline { public class DebugParamMap { private Dictionary<string, Func<object>> debugParams = new Dictionary<string, Func<object>>(); public void AddParameter(string name, Expression<Func<object>> mapping) { // mapping.Body should here be of the form // Convert - MemberAccess if (mapping.Body.NodeType == ExpressionType.Convert) { var field = (mapping.Body as UnaryExpression).Operand; if (field.NodeType == ExpressionType.MemberAccess) { AddParameter(name, field as MemberExpression); return; } } else if (mapping.Body.NodeType == ExpressionType.MemberAccess) { AddParameter(name, mapping.Body as MemberExpression); return; } throw new ArgumentException("Expression must be of the form '() => member'"); } private void AddParameter(string name, MemberExpression expr) { var obj = expr.Expression; if (obj == null) { // Then it's a static property. Assume it's good. this.debugParams.Add(name, Expression.Lambda<Func<object>>(Expression.Convert(expr, typeof(object))).Compile()); } else { Expression<Func<object>> newbie = Expression.Lambda<Func<object>>( Expression.Condition( Expression.Equal( obj, Expression.Convert(Expression.Constant(null), obj.Type) ), Expression.Convert(Expression.Constant(null), expr.Type), expr, expr.Type ) ); this.debugParams.Add(name, newbie.Compile()); } } public void Print() { foreach (var entry in this.debugParams) { Console.WriteLine("{0}: {1}", entry.Key, entry.Value()); } } } public class Test { public string Name = null; } class Program { static int something = 42; static void Main(string[] args) { var map = new DebugParamMap(); var test = new Test(); map.AddParameter("foo", () => something); map.AddParameter("testname", () => test.Name); map.Print(); } }}[/source]