0

Here is my problem,

I fetch a json from a webservice and deserialize it into an object. Now, I want this object and its values to be accessible from anywhere in the program, how can I do that ? PS: the ultimate goal being the possibility to access the user id of this object from another class.

HttpClientService clientActeur = new HttpClientService();

ActeurJson acteurJson = new ActeurJson();
acteurJson = JsonConvert.DeserializeObject<ActeurJson>(await clientActeur.loadActeur(Login,Pass));

Here are the actorJson Class and the Actor class

    public class ActeurJson
        {
            [JsonProperty("Acteur")]
            public Acteur Acteur { get; set; }
        }

public class Acteur
    {
        [JsonProperty("id")]
        public string id { get; set; }
        [JsonProperty("nom")]
        public string nom { get; set; }
        [JsonProperty("prenom")]
        public string prenom { get; set; }
        [JsonProperty("login")]
        public string login { get; set; }
        [JsonProperty("mdp")]
        public string mdp { get; set; }
        [JsonProperty("adresse")]
        public string adresse { get; set; }
        [JsonProperty("cp")]
        public string cp { get; set; }
        [JsonProperty("ville")]
        public string ville { get; set; }
        [JsonProperty("dateEmbauche")]
        public string dateEmbauche { get; set; }
        [JsonProperty("idTypeActeur")]
        public string idTypeActeur { get; set; }
        [JsonProperty("oldMdp")]
        public string oldMdp { get; set; }
        [JsonProperty("mail")]
        public string mail { get; set; }
        [JsonProperty("questionSecrete")]
        public string questionSecrete { get; set; }
        [JsonProperty("version")]
        public string version { get; set; }
    }

I already tried using the static keyword before the public class, it is not working

En_Tech_Siast
  • 83
  • 1
  • 12

1 Answers1

0

You would need to make the ActeurJson.Acteur property static. If you are going to do it your two best options are :

making it a static class

 public static class ActeurJson {
     [JsonProperty("Acteur")]
     public static Acteur Acteur { get; set; }
 }

You can make it static property of the Acteur or ActeurJson class.

public class Acteur {
    [JsonProperty("Acteur")]
    public static Acteur ActeurJson { get; set; }


    /* the rest of your class code. */
}
MBurnham
  • 381
  • 1
  • 9