Dynamic Object - Tidy property names?
I'm using some code to execute a SQL and return a IEnumerable of dynamic objects. The code is here if you want to see it.
I have a table with a column name such as APPLICATION_NAME;
开发者_C百科In my object I have to reference it like so:
var results = ReturnResults("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=rawdb;Data Source=mypc", "SELECT * FROM APPLICATIONS");
string name = results.First().APPLICATION_NAME;
Is there a way to make property names resolve to something tidier? ie.
string name = results.First().ApplicationName;
Thanks
There are some ToCamelCase()
extensions out there (just google it). But if you would implement it into your dynamic object. How do you know which shiny name you have to take for an ugly column name?
Instead you should rewrite your select statement to return nice names, instead of implementing some algorithm into the dynamic object. How about this statement:
SELECT APPLICATION_NAME as 'ApplicationName' FROM APPLICATIONS
So it is clear to everyone who reads the sql statement how to access the columns through the dynamic object.
精彩评论