Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Variable Datasource Name

Variable Datasource Name

Scheduled Pinned Locked Moved C#
cssxmltutorialquestiondiscussion
6 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eddieangel
    wrote on last edited by
    #1

    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

    L 1 Reply Last reply
    0
    • E eddieangel

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You can use XPathNavigator and XPathNodeIterator (in the System.Xml.XPath namespace) to navigate an "unknown" XML data source.

      E 1 Reply Last reply
      0
      • L Lost User

        You can use XPathNavigator and XPathNodeIterator (in the System.Xml.XPath namespace) to navigate an "unknown" XML data source.

        E Offline
        E Offline
        eddieangel
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • E eddieangel

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Then perhaps the PropertyInfo class of the System.Reflection namespace is what you're looking for ...

          E 1 Reply Last reply
          0
          • L Lost User

            Then perhaps the PropertyInfo class of the System.Reflection namespace is what you're looking for ...

            E Offline
            E Offline
            eddieangel
            wrote on last edited by
            #5

            Now THAT sounds promising. Thanks for the direction. Cheers, --EA

            L 1 Reply Last reply
            0
            • E eddieangel

              Now THAT sounds promising. Thanks for the direction. Cheers, --EA

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Also check out the MemberInfo class. One typically starts at the "member-level" (GetMembers() of the type), and then depending on the "member type" (property; method) of each member, goes from there.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups