I have a JSON class object that is an internal class. I'd like to keep it that way to keep other code from trying to create objects of that type since I only want the JSON deserialization code to do that. I can use the class type as a variable, but if I try to return an object of that type I get an inconsistent accessibiliy compiler error because the method is public and the class is internal.
What is the best way to resolve this situation? I guess I could create an interface for the internal class and pass that around, but that means I have to create extra baggage for every JSON class I am using and I'm using a lot of them.
EDIT: I made the change suggested by Jon Skeet and the problem went away. I got into this problem because of the habit of declaring my classes public by default. I'm pointing this out for others that are doing the same thing.
// The internal class.
internal class JsonPetShelters
{
[JsonProperty("@encoding")]
public string Encoding { get; set; }
[JsonProperty("@version")]
public string Version { get; set; }
[JsonProperty("petfinder")]
public Petfinder Petfinder { get; set; }
}
// This method gets the inconsistent accessibility error since
// JsonPetShelters is an internal class.
public JsonPetShelters GetShelters()
{
// For example purposes only
return null;
}