public static bool Validate <T>(PXGraph aGraph, T aAddress, bool aSynchronous, bool updateToValidAddress)
            where T : IAddressBase, IValidatedAddress
        {
            CS.Country country = PXSelect <CS.Country, Where <CS.Country.countryID, Equal <Required <CS.Country.countryID> > > > .Select(aGraph, aAddress.CountryID);

            if (string.IsNullOrEmpty(country.AddressVerificationTypeName))
            {
                if (aSynchronous)
                {
                    PXCache cache            = aGraph.Caches[typeof(T)];
                    string  countryFieldName = GetFieldName(typeof(T), Fields.CountryID);
                    cache.RaiseExceptionHandling(countryFieldName, aAddress, aAddress.CountryID,
                                                 new PXSetPropertyException(Messages.AddressVerificationServiceIsNotSetup,
                                                                            PXErrorLevel.Warning, aAddress.CountryID));
                    return(false);
                }
                else
                {
                    throw new PXException(Messages.AddressVerificationServiceIsNotSetup, aAddress.CountryID);
                }
            }

            IAddressValidationService service = Create(country);

            if (service != null)
            {
                PXCache cache = aGraph.Caches[typeof(T)];
                if (!service.IsServiceActive(aGraph))
                {
                    if (aSynchronous)
                    {
                        string countryFieldName = GetFieldName(typeof(T), Fields.CountryID);
                        cache.RaiseExceptionHandling(countryFieldName, aAddress, aAddress.CountryID,
                                                     new PXSetPropertyException(Messages.AddressVerificationServiceIsNotActive,
                                                                                PXErrorLevel.Error, aAddress.CountryID));
                        return(false);
                    }
                    else
                    {
                        throw new PXException(Messages.AddressVerificationServiceIsNotActive, aAddress.CountryID);
                    }
                }
                service.SetupService(aGraph);
                bool isValid;
                Dictionary <Fields, string> messages = new Dictionary <Fields, string>();

                T copy = (T)cache.CreateCopy(aAddress);
                if (!service.ValidateAddress(copy, out isValid, messages))
                {
                    throw new PXException(Messages.UnknownErrorOnAddressValidation);
                }
                if (isValid)
                {
                    T copyToUpdate = copy;
                    if (!updateToValidAddress)
                    {
                        copyToUpdate = (T)cache.CreateCopy(aAddress);                        //Clear changes made by ValidateAddress
                    }
                    copyToUpdate.IsValidated = true;
                    aAddress = (T)cache.Update(copyToUpdate);
                    if (!updateToValidAddress && aSynchronous)
                    {
                        string[] fields = { GetFieldName(typeof(T), Fields.AddressLine1),
                                            GetFieldName(typeof(T), Fields.AddressLine2),
                                            GetFieldName(typeof(T), Fields.City),
                                            GetFieldName(typeof(T), Fields.State),
                                            GetFieldName(typeof(T), Fields.PostalCode) };
                        foreach (string iFld in fields)
                        {
                            string ourValue = ((string)cache.GetValue(aAddress, iFld)) ?? String.Empty;
                            string extValue = ((string)cache.GetValue(copy, iFld)) ?? String.Empty;

                            if (String.Compare(ourValue.Trim(), extValue.Trim(), true) != 0)
                            {
                                cache.RaiseExceptionHandling(iFld, aAddress, ourValue,
                                                             new PXSetPropertyException(Messages.AddressVerificationServiceReturnsField, PXErrorLevel.Warning, extValue));
                            }
                        }
                    }
                }
                else
                {
                    string        message        = string.Empty;
                    StringBuilder messageBuilder = new StringBuilder();
                    int           count          = 0;
                    foreach (KeyValuePair <Fields, string> iMsg in messages)
                    {
                        string fieldName = GetFieldName(typeof(T), iMsg.Key);
                        if (!aSynchronous)
                        {
                            if (count > 0)
                            {
                                messageBuilder.Append(",");
                            }
                            messageBuilder.AppendFormat("{0}:{1}", fieldName, iMsg.Value);
                            count++;
                        }
                        else
                        {
                            object value = cache.GetValue(aAddress, fieldName);
                            cache.RaiseExceptionHandling(fieldName, aAddress, value, new PXSetPropertyException(iMsg.Value));
                        }
                    }
                    if (!aSynchronous)
                    {
                        throw new PXException(messageBuilder.ToString());
                    }
                    return(false);
                }
            }
            return(true);
        }