Service Stack Client for 3rd party needs a parameter called Public

91 views Asked by At

I have a requirement to call a 3rd party rest api using service stack and this is working fine.

But one of the rest api's requires a property called "public"

Is there an attribute I can specify to give it another name in the class but use the public name when it calls the service?

so I have this definition in the class

public string public { get; set; }

The error I get is

Member modifier 'public' must precede the member type and name

Thanks

1

There are 1 answers

0
Chris On

OK I found what I needed.

I tried the Alias attribute from ServiceStack.DataAnotations.Alias but this did nothing and I am not sure what it is for?

I then found that adding a reference to System.Runtime.Serialization was needed and also adorning the class with

[System.Runtime.Serialization.DataContract]

Now each public property needs the following attribute or it will not pass the parameter to the rest server. IN the case of the property called Public it specifies the name in the DataMember attribute constructor.

[System.Runtime.Serialization.DataMember]

Below is an example

[System.Runtime.Serialization.DataContract]
public class RequestVoiceBaseSearch : VoiceBaseBaseClass, IReturn<ResponseVoiceBaseSearch>
{
    [System.Runtime.Serialization.DataMember]
    public string action { get; set; }
    [System.Runtime.Serialization.DataMember]
    public string terms { get; set; }
    [System.Runtime.Serialization.DataMember]
    public string from { get; set; }
    [System.Runtime.Serialization.DataMember]
    public string to { get; set; }
    [System.Runtime.Serialization.DataMember(Name = "Public")]
    public bool _public { get; set; }
    [System.Runtime.Serialization.DataMember]
    public string rank { get; set; }

    public RequestVoiceBaseSearch()
        : base()
    {
        this.action = "Search";
        this.terms = "";
    }
}

Chris