Link to home
Start Free TrialLog in
Avatar of purplesoup
purplesoupFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to implement different address validation providers in .NET?

I want to be able to use different postal address validation providers for my .NET application, and want to know the best and/or easiest way.

The interface would be quite simple - probably pass in some address object to a "Verify" method and have the code check the address and modify it in some way if necessary, then perhaps pass a boolean to indicate if any modifications were made.

My problem is, I would like supporting a new address provider to not require re-supplying the original application, or not having the original source code. So it should be easy for the existing validation assembly to be replaced by another one. Perhaps have the config file (app.config or web.config) specify the assembly to use for address validation.

In COM this would be pretty simple - just have the string for the ProgId specified somewhere, then do a CreateObject(progridname) to load the code. The implementation would just have to implement some standard interface to be "swappable" - so the VB COM code would be something like:

Dim addressVerify as IAddressVerify
Dim progidname as String

progidname = ReadProviderProgId()

Set addressVerify = CreateObject(progidname)

isModified = addressVerify.Verify(myaddress)

I'm guessing something like this should be achievable with serialization or perhaps some other way - can anyone advise?

I'll be implementing this in ASP.NET but I'm assuming that shouldn't really affect the solution.

Also I am working with .NET 3.5.
Avatar of gdupadhyay
gdupadhyay
Flag of United States of America image

There is no any validator for Postal address. You have to write your own code (In client side/ or server side)
to validate postal address.

For more info: please see below URL:


http://stackoverflow.com/questions/758450/mailing-address-verification-etc-get-county-from-zip

Let me know for any question.
Avatar of purplesoup

ASKER

I haven't explained myself well. I'm not looking for some postal address software - there are many options for that - I'm looking for a design that will allow me to implement different providers and allow the application at run-time to plug in a new provider.
Oh - I meant to say "this should be achievable with reflection", not "this should be achievable with serialization" above  - sorry.
Well I've just written a little test using reflection - this is a simple calculator, but the principle is the same I guess - any comments on whether this is a good way to go or if there is a better alternative?


int i = int.Parse(textBox1.Text);
                int j = int.Parse(textBox2.Text);

                // load assembly
                Assembly calAssembly = Assembly.LoadFile(Properties.Settings.Default.AssumblyFilePath);
                Type calType = calAssembly.GetType(Properties.Settings.Default.CalculatorType);
                ICalculator calculator = Activator.CreateInstance(calType) as ICalculator;

                if (calculator != null)
                {
                    textBox3.Text = calculator.Add(i, j).ToString();    
                }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The plug-in link is basically the same code I suggested but has a few more bells and whistles.