classes as enum (or something like an enum)
-
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>
which would allow something along the lines ofif(foo.Status == StatusAdapter.NotStarted){...}
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 need to create all relevant classes required at run-time. If I used an enum I'd have to change the class library and re-deploy to all applications that use it. I cannot use an interface as was suggested here [^] simply because the consumers of the class library will not be the ones extending the list of statuses they are just needing to use the statuses I provide. Any ideas? -
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>
which would allow something along the lines ofif(foo.Status == StatusAdapter.NotStarted){...}
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 need to create all relevant classes required at run-time. If I used an enum I'd have to change the class library and re-deploy to all applications that use it. I cannot use an interface as was suggested here [^] simply because the consumers of the class library will not be the ones extending the list of statuses they are just needing to use the statuses I provide. Any ideas?Nathan Gloyn wrote:
exposes a status property on one of its classes but this property is in fact another class itself
What do you mean by this excatly, is there a subtype-per-status (good OO, but exposing the problem of translating this to Web/WCF services)? If so the following code will be possible:
ReturnObjectType value = Method();
if(value.Status is StatusType)
{
...
}_Method_
is the service method invoked_ReturnObjectType_
is the return type of the Service method call._StatusType_
is the type of the status you are looking for.CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
-
Nathan Gloyn wrote:
exposes a status property on one of its classes but this property is in fact another class itself
What do you mean by this excatly, is there a subtype-per-status (good OO, but exposing the problem of translating this to Web/WCF services)? If so the following code will be possible:
ReturnObjectType value = Method();
if(value.Status is StatusType)
{
...
}_Method_
is the service method invoked_ReturnObjectType_
is the return type of the Service method call._StatusType_
is the type of the status you are looking for.CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
No subtype just different property values. But what I wanted to do is present to users of my class library the values in a form something akin to an enum so that if they create an object and need to set the status of it you wouldn't have to use some sort of 'magic string'
-
No subtype just different property values. But what I wanted to do is present to users of my class library the values in a form something akin to an enum so that if they create an object and need to set the status of it you wouldn't have to use some sort of 'magic string'
Pity. The "magic string" effect is a consequence of [good] advice from Microsoft WRT to maintainability of the service. If they had exposed an enum, adding new values would involve re-gen'ing the client & rebuild, also the numeric values of the enums can change. Really the message contract types aren't OO'd in the full sense, they are close to object like data bags. To get round this problem we have converters to convert Data Contracts from the server to pukka objects on the client side. This can be automated with a bit thought.
CCC solved so far: 2 (including a Hard One!) 37!?!! - Randall, Clerks
-
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>
which would allow something along the lines ofif(foo.Status == StatusAdapter.NotStarted){...}
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 need to create all relevant classes required at run-time. If I used an enum I'd have to change the class library and re-deploy to all applications that use it. I cannot use an interface as was suggested here [^] simply because the consumers of the class library will not be the ones extending the list of statuses they are just needing to use the statuses I provide. Any ideas?Make a static class that exposes properties that are of the proper type?
public static class StatusWrapper
{
private static StatusClass notstarted = new StatusClass ( whatever means not started ) ;public static StatusClass NotStarted { get { return notstarted ; } } ...
}
StatusClass status = StatusWrapper.NotStarted ;
Or, if that's too ummm... static... the wrapper could use a Dictionary to map enumerated values to the status type.
-
Make a static class that exposes properties that are of the proper type?
public static class StatusWrapper
{
private static StatusClass notstarted = new StatusClass ( whatever means not started ) ;public static StatusClass NotStarted { get { return notstarted ; } } ...
}
StatusClass status = StatusWrapper.NotStarted ;
Or, if that's too ummm... static... the wrapper could use a Dictionary to map enumerated values to the status type.
Thanks PIEBALDconsult both of those answers may be of some use, I must admit to leaning towards the dictionary simply because its a) simple b) can hold as many statuses as the user may want to create. Admittedly not sure how the end developer may interact with the dictionary but perhaps thats me just being dumb as not coded it yet. :)