Browse Source

More readme examples

Brad Robinson 11 years ago
parent
commit
332026b47b
1 changed files with 24 additions and 1 deletions
  1. 24 1
      readme.md

+ 24 - 1
readme.md

@@ -21,7 +21,8 @@ PetaJson is a simple but flexible JSON library implemented in a single C# file.
 ## Setup
 
 1. Add PetaJson.cs to your project
-2. That's it
+2. Optionally add "using PetaJson;" clauses as required
+3. That's it
 
 ## Generating JSON
 
@@ -140,6 +141,28 @@ Use the JsonExclude attribute to exclude public fields/properties from serializa
 		}
 	}
 
+Sometimes you'll want sub-objects to be serialized into the existing object instance.
+
+eg: 
+
+	class MyApp
+	{
+		public MyApp()
+		{
+			// Settings object has an owner pointer back to this so during
+			// serialization we don't want to create a new instance of the settings
+			// object.
+			CurrentSettings = new Settings(this);
+		}
+
+		[Json(KeepInstance=true)]
+		Settings CurrentSettings;
+	}
+
+In this example the existing CurrentSettings object will be instantiated into. If KeepInstance
+was set to false, PetaJson would instantiate a new Settings object, load it and then assign
+it to the CurrentSettings property.
+
 
 ## Custom Formatting