3

I'm trying to parse a json file that contains a parameter named ref. I'm deserializing into a class structure:

public class JiveContentObject
{
   public int id { get; set;}
   public string subject { get; set;}
   ..etc
}

however, I can't exactly write public string ref {get; set;} since ref is a keyword in c#. Is there any way I can work around this?

Ondrej Tucny
  • 27,626
  • 6
  • 70
  • 90
creitz
  • 31
  • 1
  • 3
    just write `@ref`. prepending `@` is how you work around reserved keywords. however it would be better to make use of some kind of middleware mapping – Andrei May 05 '15 at 20:32
  • A question that is not a duplicate of this one, but whose accepted answer applies: http://stackoverflow.com/questions/421257/how-do-i-use-a-c-sharp-keyword-as-a-property-on-an-anonymous-object – phoog May 05 '15 at 21:49

1 Answers1

7

Prefix the identifier with @:

public class JiveContentObject
{
    public int id { get; set; }
    public string subject { get; set; }
    public string @ref { get; set; }
}

This is exactly what it's there for.

Servy
  • 202,030
  • 26
  • 332
  • 449