B
Bernard
I have an xml fragment that looks like this assigned to doc variable:
<charge_details>
<charge>
<type>Maintenance Charge</type>
<currency>GBP</currency>
<percentage>0.35000</percentage>
<frequency>Monthly</frequency>
<term>31</term>
<lower_bound>500000.00</lower_bound>
<upper_bound>999999.99</upper_bound>
</charge>
<charge>
<type>Maintenance Charge</type>
<currency>GBP</currency>
<percentage>0.35000</percentage>
<frequency>Monthly</frequency>
<term>31</term>
<lower_bound>500000.00</lower_bound>
<upper_bound>999999.99</upper_bound>
</charge>
<charge>
<type>Quarterly Admin Charge</type>
<currency>GBP</currency>
<percentage>22.00000</percentage>
<frequency />
</charge>
<charge>
<type>Dealing Settlement Charge</type>
<currency>GBP</currency>
<charge_amount>22.00</charge_amount>
<frequency />
</charge>
</charge_details>
I have a LINQ query that looks like this:
IList<PolicyTerm> policyTerms = (from MMPPolicyTerms in
doc.Elements("charge_details").Elements("charge")
select new PolicyTerm
{
PolicyTermType =
(PolicyTermType)(StringEnum.Parse(typeof(PolicyTermType),
MMPPolicyTerms.Element("type").Value)),
Percentage = (double?)MMPPolicyTerms.Element("percentage") ??
0.00,
Currency = (string)MMPPolicyTerms.Element("currency") ??
string.Empty,
Amount = (double?)MMPPolicyTerms.Element("charge_amount") ??
0.00,
Term = (string)MMPPolicyTerms.Element("term") ?? string.Empty
}).ToList();
And I keep getting an exception being thrown...I'm assuming because some of
the nodes aren't always there?
I thought I would be able to get around it by using the ?? operator.
The class PolicyTerm is asimple one that looks like this:
public class PolicyTerm
{
public PolicyTermType PolicyTermType { get; set; }
public double? Percentage { get; set; }
public double? Amount { get; set; }
public string Currency { get; set; }
public string Term { get; set; }
}
Does anyone have any suggestions as to what I can do to avoid this? I know I
can choose not to use ToList but then I just get the error thrown when I
enumerate when I bind on the front end
<charge_details>
<charge>
<type>Maintenance Charge</type>
<currency>GBP</currency>
<percentage>0.35000</percentage>
<frequency>Monthly</frequency>
<term>31</term>
<lower_bound>500000.00</lower_bound>
<upper_bound>999999.99</upper_bound>
</charge>
<charge>
<type>Maintenance Charge</type>
<currency>GBP</currency>
<percentage>0.35000</percentage>
<frequency>Monthly</frequency>
<term>31</term>
<lower_bound>500000.00</lower_bound>
<upper_bound>999999.99</upper_bound>
</charge>
<charge>
<type>Quarterly Admin Charge</type>
<currency>GBP</currency>
<percentage>22.00000</percentage>
<frequency />
</charge>
<charge>
<type>Dealing Settlement Charge</type>
<currency>GBP</currency>
<charge_amount>22.00</charge_amount>
<frequency />
</charge>
</charge_details>
I have a LINQ query that looks like this:
IList<PolicyTerm> policyTerms = (from MMPPolicyTerms in
doc.Elements("charge_details").Elements("charge")
select new PolicyTerm
{
PolicyTermType =
(PolicyTermType)(StringEnum.Parse(typeof(PolicyTermType),
MMPPolicyTerms.Element("type").Value)),
Percentage = (double?)MMPPolicyTerms.Element("percentage") ??
0.00,
Currency = (string)MMPPolicyTerms.Element("currency") ??
string.Empty,
Amount = (double?)MMPPolicyTerms.Element("charge_amount") ??
0.00,
Term = (string)MMPPolicyTerms.Element("term") ?? string.Empty
}).ToList();
And I keep getting an exception being thrown...I'm assuming because some of
the nodes aren't always there?
I thought I would be able to get around it by using the ?? operator.
The class PolicyTerm is asimple one that looks like this:
public class PolicyTerm
{
public PolicyTermType PolicyTermType { get; set; }
public double? Percentage { get; set; }
public double? Amount { get; set; }
public string Currency { get; set; }
public string Term { get; set; }
}
Does anyone have any suggestions as to what I can do to avoid this? I know I
can choose not to use ToList but then I just get the error thrown when I
enumerate when I bind on the front end