Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reflection Question #2
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01473954
Message ID:
01474004
Views:
42
>This is a bit long, but I'm lost/stuck and need help.
>
>I have data stored in XML format in SQL. I ommitted some of the empty rows for brevity:
>
>
><SuperCollectionClass xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/ConfigManager.ChangeSetEngine">
>  <CustomConfigurations xmlns:d2p1="http://schemas.datacontract.org/2004/07/ConfigManager.ChangeSetEngine.Objects" />
>  <LastInternalPrimaryKey>0</LastInternalPrimaryKey>
>  <LkpPresortLocations i:nil="true" />
>  <LkpPrinterInkColors />
>  <MmlDepartmentForms i:nil="true" />
>  <MmlDepartmentImportFileTypes i:nil="true" />
>  <TblAppPubFiles i:nil="true" />
>  <TblCompanys />
>  <TblConfirmBatches i:nil="true" />
>  <TblConsumableVersions i:nil="true" />
>  <TblDataExports />
>  <TblDepartmentAddresses>
>    <TblDepartmentAddress>
>      <InternalPrimaryKeyValue i:nil="true" />
>      <RowState>Update</RowState>
>      <DepartmentAddressID>205</DepartmentAddressID>
>      <DepartmentID>4</DepartmentID>
>      <Name>New Return Address Proj 1</Name>
>      <AddressTypeID>2</AddressTypeID>
>      <CountryCodeID>1</CountryCodeID>
>      <Address1>PO Box 9044</Address1>
>      <Address2 i:nil="true" />
>      <Address3 i:nil="true" />
>      <City>Temecula</City>
>      <State>CA</State>
>      <Zip>92589-9044</Zip>
>      <DataVersion xmlns:d4p1="http://schemas.datacontract.org/2004/07/System.Data.Linq">
>        <d4p1:Bytes>AAAAAAAAz+g=</d4p1:Bytes>
>      </DataVersion>
>    </TblDepartmentAddress>
>  </TblDepartmentAddresses>
>  <TblDepartmentExports />
>  <TblRecordIndicatorMaps i:nil="true" />
>  <TblRecordIndicators />
>  <TblSubLetterIndicators i:nil="true" />
>  <TblSubLetters i:nil="true" />
></SuperCollectionClass>
>
>
>The data is deserialized into a collection of SuperCollectionClass objects. For any node that has children, such as
>TblDepartmentAddresses above, I want to iterate through the data rows. So far I have this working:
>
>
>PropertyInfo[] Properties = typeof(SuperCollectionClass).GetProperties();
>foreach (var property in Properties)
>{
>    // PropertyName will contain the name of a table node 
>    string PropertyName = property.Name.ToLower();
>
>    if (PropertyName.Substring(0, 3) == "lkp" ||
>        PropertyName.Substring(0, 3) == "mml" ||
>        PropertyName.Substring(0, 3) == "tbl")
>    {
>        // Value will not be null if there are child nodes
>        var Value = property.GetValue(ProjectManager.Instance.ReconciledData, null);
>
>        if (Value != null)
>        {
>            // What goes here? How do I iterate through the child nodes??
>        }
>    }
>}
>
I don't understand why you are using reflection here. Since you use
typeof(SuperCollectionClass).GetProperties();
rather than
ProjectManager.Instance.ReconciledData.GetType().GetProperties()
it implies that you are already aware of the class type....
Previous
Reply
Map
View

Click here to load this message in the networking platform