Comments
2 comments
- 
                
                   The code Reflector is generating is incorrect. It is trying to do the equivalent of the following, which does compile. The code Reflector is generating is incorrect. It is trying to do the equivalent of the following, which does compile.
 public Program(Func<string>x)
 {
 }
 public Program(string errorMessage)
 : this(() => errorMessage)
 {
 }
 Ie the stuff to do with the local variable func, is supposed to be happening inside the call to this(…)
 By the way, we also have a newer forum here: http://forums.reflector.net/  
- 
                
                   Thanks for the reply Nick. I figured as much that all the logic was inlined. I was hoping there was some special trick we could use to have more complex "default" parameters we could pass to a constructor initializer. Thanks for the reply Nick. I figured as much that all the logic was inlined. I was hoping there was some special trick we could use to have more complex "default" parameters we could pass to a constructor initializer.
Add comment
Please sign in to leave a comment.
The ctors look off. I'm pretty sure this is how the code is behaving as the late bound Func<string> around the message is clearly working.
How is "func" passed to the ctor initializer *before* it is declared.
protected ValidationAttribute(string errorMessage) : this(func) { Func<string> func = null; if (func == null) { func = () => errorMessage; } }It would be amazing if we could apply complex default logic to pass to ctor initializer.
I tried doing this and it doesn't compile.