Click here to Skip to main content
15,892,161 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Sound of the Week Pin
Sander Rossel7-Sep-19 1:02
professionalSander Rossel7-Sep-19 1:02 
GeneralRe: Sound of the Week Pin
phil.o7-Sep-19 1:15
professionalphil.o7-Sep-19 1:15 
GeneralRe: Sound of the Week Pin
Slacker0076-Sep-19 0:35
professionalSlacker0076-Sep-19 0:35 
GeneralRe: Sound of the Week Pin
Sander Rossel6-Sep-19 1:01
professionalSander Rossel6-Sep-19 1:01 
GeneralRe: Sound of the Week Pin
User 48350476-Sep-19 4:19
User 48350476-Sep-19 4:19 
GeneralRe: Sound of the Week Pin
Sander Rossel7-Sep-19 0:48
professionalSander Rossel7-Sep-19 0:48 
GeneralRe: Sound of the Week Pin
peterkmx7-Sep-19 5:58
professionalpeterkmx7-Sep-19 5:58 
Generali love JSON. i'm not sure the relationship is healthy though Pin
honey the codewitch5-Sep-19 19:22
mvahoney the codewitch5-Sep-19 19:22 
It's a torrid affair. I've begun using JSON to back entity objects and after doing so I don't think I'm ever going back.

Jeez it's cool tho.

I'm addicted. Maybe I need help.

This is just exciting.

At the risk of dropping some code here:

an example of one (read-only in this case, but adding writing is doable too)

C#
public abstract class TmdbEntity : IEquatable<TmdbEntity>
{
	protected TmdbEntity(IDictionary<string, object> json)
	{
		Json = json ?? throw new ArgumentNullException(nameof(json));
	}
		
	public IDictionary<string, object> Json { get; protected set; }

		
	protected T GetField<T>(string name,T @default=default(T))
	{
		object o;
		if (Json.TryGetValue(name, out o) && o is T)
			return (T)o;
		return @default;
	}
	// objects are considered equal if they
	// point to the same actual json reference
	public bool Equals(TmdbEntity rhs)
	{
		if (ReferenceEquals(this, rhs))
			return true;
		if (ReferenceEquals(rhs, null))
			return false;
		return ReferenceEquals(Json, rhs.Json);
	}
	public override bool Equals(object obj)
	{
		return Equals(obj as TmdbEntity);
	}
	public static bool operator==(TmdbEntity lhs, TmdbEntity rhs)
	{
		return lhs.Equals(rhs);
	}
	public static bool operator!=(TmdbEntity lhs, TmdbEntity rhs)
	{
		return !lhs.Equals(rhs);
	}
	public override int GetHashCode()
	{
		// we need the actual base hashcode, not the one
		// computed by the JsonObject.
		var jo = Json as JsonObject; // should always be but it doesn't *have* to be
		if(null!=jo)
		{
			jo.BaseDictionary.GetHashCode();
		}
		return Json.GetHashCode();
	}
}


Then in your derived classes:
C#
public class TmdbLanguage : TmdbEntity
{
	public TmdbLanguage(IDictionary<string,object> json) : base(json)
	{
	}
	public string Name => GetField<string>("name");
	public string EnglishName => GetField<string>("english_name");
	public string Iso => GetField<string>("iso_639_1");

}


Then on any entity you can also get the Json property to get all of the actual data for your object as one unit, which you can then query on. This makes it better than traditional entities that consume and toss or otherwise hide the underlying data structure, frankly. It's not only more "pure" to back your state with the actual data you got, it's also easier to query on it or update it. By query it i mean do like "JsonObject.Select(myEntity.Json,"$.id")" if you want or "myEntity.Id"

So, do I need help?
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

JokeRe: i love JSON. i'm not sure the relationship is healthy though Pin
Nelek5-Sep-19 19:33
protectorNelek5-Sep-19 19:33 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
honey the codewitch5-Sep-19 19:35
mvahoney the codewitch5-Sep-19 19:35 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
Jörgen Andersson5-Sep-19 21:21
professionalJörgen Andersson5-Sep-19 21:21 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
honey the codewitch5-Sep-19 21:35
mvahoney the codewitch5-Sep-19 21:35 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
Jörgen Andersson5-Sep-19 23:25
professionalJörgen Andersson5-Sep-19 23:25 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
honey the codewitch5-Sep-19 23:28
mvahoney the codewitch5-Sep-19 23:28 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
Jörgen Andersson5-Sep-19 23:36
professionalJörgen Andersson5-Sep-19 23:36 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
honey the codewitch5-Sep-19 23:38
mvahoney the codewitch5-Sep-19 23:38 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
Sander Rossel5-Sep-19 20:37
professionalSander Rossel5-Sep-19 20:37 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
honey the codewitch5-Sep-19 20:43
mvahoney the codewitch5-Sep-19 20:43 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
Slacker0075-Sep-19 21:44
professionalSlacker0075-Sep-19 21:44 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
honey the codewitch5-Sep-19 23:36
mvahoney the codewitch5-Sep-19 23:36 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
Slacker0076-Sep-19 0:31
professionalSlacker0076-Sep-19 0:31 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
honey the codewitch6-Sep-19 0:34
mvahoney the codewitch6-Sep-19 0:34 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
Slacker0076-Sep-19 0:40
professionalSlacker0076-Sep-19 0:40 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
honey the codewitch6-Sep-19 0:40
mvahoney the codewitch6-Sep-19 0:40 
GeneralRe: i love JSON. i'm not sure the relationship is healthy though Pin
Slacker0076-Sep-19 0:43
professionalSlacker0076-Sep-19 0:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.