Variable Datasource Name
-
I am trying to make a fairly robust file writer. I want to specify the format of the file in an XML file. I need to be able to get the datasource name dynamically from the XML file, the XML will look something like this:
I am not sure what that data will look like. It might be a list, it might be a single object, but I want to be able to enumerate it's properties in my class. Something like this:
var data = data.GetType().GetProperty(fieldName).GetValue(data, null).ToString()
I have most of the code ironed out, just not sure how to handle the data source. I could make it less generic and take the data source name out of the XML and just handle it code side, but I like the robustness of having the instructions all XML contained. Thoughts? Cheers, --EA
-
I am trying to make a fairly robust file writer. I want to specify the format of the file in an XML file. I need to be able to get the datasource name dynamically from the XML file, the XML will look something like this:
I am not sure what that data will look like. It might be a list, it might be a single object, but I want to be able to enumerate it's properties in my class. Something like this:
var data = data.GetType().GetProperty(fieldName).GetValue(data, null).ToString()
I have most of the code ironed out, just not sure how to handle the data source. I could make it less generic and take the data source name out of the XML and just handle it code side, but I like the robustness of having the instructions all XML contained. Thoughts? Cheers, --EA
-
You can use XPathNavigator and XPathNodeIterator (in the System.Xml.XPath namespace) to navigate an "unknown" XML data source.
I should have explained better. The instructions are XML, but the datasource could be any number of things. It is either a List or just an Object. If it is an object I want to get at it's properties as in the c# code I posted below, if it is a List then I will loop through it and access it the same way. Just need to figure out how to access that data by name.
-
I should have explained better. The instructions are XML, but the datasource could be any number of things. It is either a List or just an Object. If it is an object I want to get at it's properties as in the c# code I posted below, if it is a List then I will loop through it and access it the same way. Just need to figure out how to access that data by name.
-
Then perhaps the PropertyInfo class of the System.Reflection namespace is what you're looking for ...
Now THAT sounds promising. Thanks for the direction. Cheers, --EA
-
Now THAT sounds promising. Thanks for the direction. Cheers, --EA