• Share
    • Twitter
    • LinkedIn
    • Facebook
    • Email
  • Feedback
  • Edit
Show / Hide Table of Contents

AddressHelper class

Some tooltip text!
• 1 minute to read
 • 1 minute to read

Each of the extension methods to set LocalizedAddress depends on a helper class called AddressHelper. The sole purpose of this class is to make it easy to get an Address as a Dictionary and transform a Dictionary into an Address.

public class AddressHelper
{
  public Dictionary<string, string> GetAddressAsDictionary(Address address)
  {
    ValidateAddress(address);
    var result = new Dictionary<string, string>(14);

    foreach (var line in address.LocalizedAddress)
    {
      foreach (var field in line)
      {
        result.Add(field.Name, field.Value);
      }
    }
    return result;
  }

  public void SetAddressFromDictionary(Address address, Dictionary<string, string> addressInfo)
  {
    ValidateAddress(address);

    foreach (var line in address.LocalizedAddress)
    {
      foreach (var field in line)
      {
        if (addressInfo.ContainsKey(field.Name))
          field.Value = addressInfo[field.Name];
        }
      }
    }

  private void ValidateAddress(Address address)
  {
    if ( address == null
      || address.LocalizedAddress == null
      || address.LocalizedAddress.Length == 0)
      throw new Exception("Must provide a formatted Address");
  }
}
In This Article
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top