i'm looking for which how to visual studio generate code when u are working on design mode. for example, suppose u have a web project with visual studio, when u add gridView to yout web page, it generate aspx code in .aspx file on the specific line of page, when u change some default properties of gridView, it add code to .aspx, and when u delete gridView, it delete gridView code that wrote to aspx file. i'm looking for a best way to accomplish this (user design form and my application generate aspx code for it).
can anybody help me ?
i'm looking for a best way to accomplish this (user design form and my application generate aspx code for it).
If I understand your question correctly, you want to design an applcation that does the same as Visual Studio. It would allow a user to drag and drop controls onto a form, and your application would generate the actual aspx code, to make it run. This is not a trivial task, IMHO, as you will need to create libaries of classes for all the tools you are to offer, with each class having the properties necessary to generate the images and the code.
It depends on the complexity of the case. I'd definitely avoid the second condition because debugging nested ternary's is an absolute nightmare. In a more complex case than this though, I'd drop both constructs in favour of an Action or Func. Have a look at the Log class in my article here[^] to see how it works.
The basic approach is to set up a set of Actions (or Funcs) that correspond to the operations in your switch statement and assign them to a dictionary (the key in the dictionary is the value for your switch statement). All you need do then is trigger the appropriate action based on the key. In the log sample, this line actually performs the validation:
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
clarity and readability are much more important than saving space on screen.
Which is why I posted - As the ?: was/is very clear to me, and I can at a glance understand what's going on, but I'm well aware it's not a construct used that/as often, so wanted to test the waters with other coders.
-debugging nested ternary's is an absolute nightmare
-I'll go for Switch because its easy to track errors in that.
As this is a *very* simple case I didn't even think of that actually.
But it might need to get more complicated as the code evolves.
Where I'm using it, it's not very likely though - But those are "famous last words", so point taken and agreed to.
Thank you all for the feed back - I'll tidy up my code now
As others said switch is more readable in this case. Also when switch has more labels, compilers use a lookup table (probably hash tables) to implement that and it will yield in accessing all the labels in constant time.