Reflect and Load code at design time in Visual Studio
I have an XML file that lists a series of items, and the items are often referenced by their name in code.
Is there any way to use reflection within Visual Studio to make this list 'accessible' sort of like intellisence? I've seen it don开发者_开发技巧e before - and I'm pretty sure it's ridiculously difficult, but I figure it can't hurt to at least ask.
I would recommend against using reflection for this.
Apart from the added complexity in the code you are also opening the code up to abuse from somebody modifying your XML to get your code to do what they want (think injection attack).
You would be better off parsing the XML as usual but using a big if / switch statement to define what how the code runs. That way you have more chance of catching any problems and validating the input.
From string to function call sounds great but will bite you in the bum.
I think he wants to access xml from c# code with intelligences.
My guess is that you would have to build some sort of code generator that would generate c# class that has the properties of you xml field... kind of how visual studio generates code for resourcefiles.
精彩评论