L
lsavidge
Guest
Ok, the subject is quite broad. I'll explain. I have a class here:
namespace ACLWebApi.CustomClasses.CustomersBalances
{
using System.Xml.Serialization;
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public class CustomersBalances
{
public string Odatacontext { get; set; }
public CustomerBalances[] Value { get; set; }
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public class CustomerBalances
{
public string CustomerNumber { get; set; }
public string Terms { get; set; }
public long CreditLimitCustomerCurrency { get; set; }
public float BalanceDueInCustomerCurrency { get; set; }
public float BalanceDueInFunctionalCurrency { get; set; }
}
}
It was created from an XSD. You can see the two float values and the long values. When I make a call into my Sage application, I query an API that returns me an array of customers that deserialise straight into an object of type customerBalances. The data types are fixed by Sage.
Potentially, there could be many thousands of customer records. I need to return the values for the credit limit, and customer balances so that they are all multiplied up by 100 and then returned as integer values. This is because the client that calls my function has implied decimal places, so, for example if the credit limit is 100,000, they store the value in their system as 10000000 which equates to 100,000.00. Same for the balances. They currently come as floats but I need to mutlply up by 100 and convert to integers.
I could quite easily take the customerBalances array and loop through it each time and make the change to the values as I return an XML doc. An example of one customer is here:
<CustomersBalances>
<CustomerBalances>
<CustomerNumber>CustomerA</CustomerNumber>
<Terms>0</Terms>
<CreditLimitCustomerCurrency>100000</CreditLimitCustomerCurrency>
<BalanceDueInCustomerCurrency>2500.89</BalanceDueInCustomerCurrency>
<BalanceDueInFunctionalCurrency>2500.89</BalanceDueInFunctionalCurrency>
</CustomerBalances>
</CustomersBalances>
If there were many thousands of customers I don't want to loop through to alter them if I can help it. I'm wondering if there is a way to alter the class to return them in the right format. So setting the values is normal, but when a get occurs they come out with the corrected values. So my example above would be:
<CustomersBalances>
<CustomerBalances>
<CustomerNumber>CustomerA</CustomerNumber>
<Terms>0</Terms>
<CreditLimitCustomerCurrency>10000000</CreditLimitCustomerCurrency>
<BalanceDueInCustomerCurrency>250089</BalanceDueInCustomerCurrency>
<BalanceDueInFunctionalCurrency>250089</BalanceDueInFunctionalCurrency>
</CustomerBalances>
</CustomersBalances>
Is there a way to avoid having a function to loop through the customerBalances array?
The code that deserialises the data is:
CustomerBalances[] customerBalances = new CustomerBalances[] { JsonConvert.DeserializeObject<CustomerBalances>(ResponsePayload) };
Continue reading...
namespace ACLWebApi.CustomClasses.CustomersBalances
{
using System.Xml.Serialization;
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public class CustomersBalances
{
public string Odatacontext { get; set; }
public CustomerBalances[] Value { get; set; }
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
public class CustomerBalances
{
public string CustomerNumber { get; set; }
public string Terms { get; set; }
public long CreditLimitCustomerCurrency { get; set; }
public float BalanceDueInCustomerCurrency { get; set; }
public float BalanceDueInFunctionalCurrency { get; set; }
}
}
It was created from an XSD. You can see the two float values and the long values. When I make a call into my Sage application, I query an API that returns me an array of customers that deserialise straight into an object of type customerBalances. The data types are fixed by Sage.
Potentially, there could be many thousands of customer records. I need to return the values for the credit limit, and customer balances so that they are all multiplied up by 100 and then returned as integer values. This is because the client that calls my function has implied decimal places, so, for example if the credit limit is 100,000, they store the value in their system as 10000000 which equates to 100,000.00. Same for the balances. They currently come as floats but I need to mutlply up by 100 and convert to integers.
I could quite easily take the customerBalances array and loop through it each time and make the change to the values as I return an XML doc. An example of one customer is here:
<CustomersBalances>
<CustomerBalances>
<CustomerNumber>CustomerA</CustomerNumber>
<Terms>0</Terms>
<CreditLimitCustomerCurrency>100000</CreditLimitCustomerCurrency>
<BalanceDueInCustomerCurrency>2500.89</BalanceDueInCustomerCurrency>
<BalanceDueInFunctionalCurrency>2500.89</BalanceDueInFunctionalCurrency>
</CustomerBalances>
</CustomersBalances>
If there were many thousands of customers I don't want to loop through to alter them if I can help it. I'm wondering if there is a way to alter the class to return them in the right format. So setting the values is normal, but when a get occurs they come out with the corrected values. So my example above would be:
<CustomersBalances>
<CustomerBalances>
<CustomerNumber>CustomerA</CustomerNumber>
<Terms>0</Terms>
<CreditLimitCustomerCurrency>10000000</CreditLimitCustomerCurrency>
<BalanceDueInCustomerCurrency>250089</BalanceDueInCustomerCurrency>
<BalanceDueInFunctionalCurrency>250089</BalanceDueInFunctionalCurrency>
</CustomerBalances>
</CustomersBalances>
Is there a way to avoid having a function to loop through the customerBalances array?
The code that deserialises the data is:
CustomerBalances[] customerBalances = new CustomerBalances[] { JsonConvert.DeserializeObject<CustomerBalances>(ResponsePayload) };
Continue reading...