views:

107

answers:

2

I'm working with a third party web service that exposes a status property on one of its classes but this property is in fact another class itself.

Whilst this is no great shakes I'm trying to make use of this web service easier for other developers in the company since the web service is abstracted away and we have our own adapter classes exposing just the properties/methods we need and I have been trying to come up with a way that will allow me to treat the status object much like a enum

What I would like to end up with is something like object.status = StatusAdapter.<value>

Before anybody says 'simply use an enum' the reason I am not simply using an enum is that the status data that the web service object represents can be added to by a user at any time which means that I'd have to change the class library and re-deploy to all applications that use it.

Any ideas?

Edit To clarify I want the end developers to be able to do the following, along the lines of an enum when StatusAdapter is not an enum but populated dynamically at run time.

If(foo.Status == StatusAdapter.NotStarted){...}
+5  A: 

Use Interface. That should do the job.

Take for example, do this

public interface IStatus
{
}

public class SuccessStatus: IStatus
{
}

public class FailStatus: IStatus
{
}

in your class, you can do this:

public class CheckWebService
{
  public IStatus Status
  {get;set;}

}

So anyone using your class can do this easily:

  var checking = new CheckWebService();
   checking.Status=new SuccessStatus();

Or define their own status which is inherited from IStatus and use it.

In this way you don't have to redeploy your code and yet still able to let users define their own statuses.

Ngu Soon Hui
The users won't be defining their own statuses the code has to be able to handle the web service returning previously unknown statuses, if I were to use an interface I would still have to change the class library and redploy. I have editing my original question to reflect this.
Nathan
A: 

The only way would be to have a number of properties on StatusAdapter which are of type StatusAdapter and return different values of StatusAdapter

Tim
Tim can you provide some more detail on this approach
Nathan