From 2045b61e59e3a0526b73ea5c8c81cc272c915f1f Mon Sep 17 00:00:00 2001 From: Sidharth Gupta Date: Wed, 20 Apr 2016 20:55:22 +0900 Subject: [PATCH] [Bundle] Add code examples for documentation Signed-off-by: Sidharth Gupta Change-Id: I180425372ea06f85828c7ddad1c5a25b1bd825b4 --- Tizen.Applications/Tizen.Applications/Bundle.cs | 136 ++++++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/Tizen.Applications/Tizen.Applications/Bundle.cs b/Tizen.Applications/Tizen.Applications/Bundle.cs index fd55bdc..723e9a3 100644 --- a/Tizen.Applications/Tizen.Applications/Bundle.cs +++ b/Tizen.Applications/Tizen.Applications/Bundle.cs @@ -31,6 +31,9 @@ namespace Tizen.Applications /// The Bundle constructor. /// /// Thrown when out of memory + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// public Bundle() { _handle = Interop.Bundle.Create(); @@ -89,6 +92,11 @@ namespace Tizen.Applications /// /// The number of items in a Bundle object. /// + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// bundle.AddItem("string", "a_string"); + /// Console.WriteLine("There are {0} items in the bundle", bundle.Count); + /// public int Count { get @@ -100,6 +108,17 @@ namespace Tizen.Applications /// /// The keys in a Bundle object. /// + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// bundle.AddItem("string1", "a_string1"); + /// bundle.AddItem("string2", "a_string2"); + /// bundle.AddItem("string3", "a_string3"); + /// Console.WriteLine("The bundle contains the following keys:"); + /// foreach(string key in bundle.Keys) + /// { + /// Console.WriteLine(key); + /// } + /// public IEnumerable Keys { get @@ -130,6 +149,15 @@ namespace Tizen.Applications /// /// The key to check for. /// true if the bundle contains the key. false otherwise. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// bundle.AddItem("string", "a_string"); + /// if (bundle.Contains("string")) + /// { + /// string aValue = bundle.GetItem("string"); + /// Console.WriteLine(aValue); + /// } + /// public bool Contains(string key) { return _keys.Contains(key); @@ -142,6 +170,11 @@ namespace Tizen.Applications /// The value of the item. /// Thrown when the key already exists or when there is an invalid parameter. /// Thrown when out of memory or when the Bundle instance has been disposed. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// byte[] byteArray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + /// bundle.AddItem("byte_array", byteArray); + /// public void AddItem(string key, byte[] value) { AddItem(key, value, 0, value.Length); @@ -157,6 +190,11 @@ namespace Tizen.Applications /// Thrown when the offset or count is out of range. /// Thrown when the key already exists or when there is an invalid parameter. /// Thrown when out of memory or when the Bundle instance has been disposed. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// byte[] byteArray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + /// bundle.AddItem("byte_array", byteArray, 2, 3); + /// public void AddItem(string key, byte[] value, int offset, int count) { if (!_keys.Contains(key)) @@ -195,6 +233,10 @@ namespace Tizen.Applications /// The value of the item. /// Thrown when the key already exists or when there is an invalid parameter. /// Thrown when out of memory or when the Bundle instance has been disposed. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// bundle.AddItem("string", "a_string"); + /// public void AddItem(string key, string value) { if (!_keys.Contains(key)) @@ -216,6 +258,11 @@ namespace Tizen.Applications /// The value of the item. /// Thrown when the key already exists or when there is an invalid parameter. /// Thrown when out of memory or when the Bundle instance has been disposed. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// string[] stringArray = { "a", "b", "c" }; + /// bundle.AddItem("string_array", stringArray); + /// public void AddItem(string key, IEnumerable value) { if (!_keys.Contains(key)) @@ -238,6 +285,19 @@ namespace Tizen.Applications /// The value of the bundle item. /// Thrown when the key does not exist or when there is an invalid parameter. /// Thrown when the Bundle instance has been disposed. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// bundle.AddItem("string", "a_string"); + /// if (bundle.Contains("string")) + /// { + /// object aValue = bundle.GetItem("string"); + /// if (bundle.Is("string");) + /// { + /// string aString = (string)aValue; + /// Console.WriteLine(aString); + /// } + /// } + /// public object GetItem(string key) { if (_keys.Contains(key)) @@ -292,6 +352,25 @@ namespace Tizen.Applications /// Thrown when the key does not exist or when there is an invalid parameter. /// Thrown when the value of the bundle item cannot be converted to the specified generic type. /// Thrown when the Bundle instance has been disposed. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// string[] stringArray = { "a", "b", "c" }; + /// bundle.AddItem("string_array", stringArray); + /// if (bundle.Is("string_array")) + /// { + /// Console.WriteLine("It is a string"); + /// Console.WriteLine(bundle.GetItem("string_array")); + /// } + /// else if (bundle.Is("string_array")) + /// { + /// Console.WriteLine("It is a string[]"); + /// string[] anArray = bundle.GetItem("string_array"); + /// foreach (string value in anArray) + /// { + /// Console.WriteLine(value); + /// } + /// } + /// public T GetItem(string key) { return (T)GetItem(key); @@ -304,6 +383,16 @@ namespace Tizen.Applications /// The value of the bundle item. If the key does not exist or the type of this parameter is incorrect, it is the default value for the value parameter type. /// true if an item with the key exists and if the value is the same type as the output value parameter. false otherwise. /// Thrown when the Bundle instance has been disposed. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// byte[] byteArray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + /// bundle.AddItem("byte_array", byteArray); + /// byte[] aByteArray; + /// if (bundle.TryGetItem("byte_array", out aByteArray)) + /// { + /// Console.WriteLine("First item in the byte array: {0}", aByteArray[0]); + /// } + /// public bool TryGetItem(string key, out byte[] value) { if (_keys.Contains(key) && Interop.Bundle.GetType(_handle, key) == (int)BundleType.Byte) @@ -329,6 +418,15 @@ namespace Tizen.Applications /// The value of the bundle item. If the key does not exist or the type of this parameter is incorrect, it is the default value for the value parameter type. /// true if an item with the key exists and if the value is the same type as the output value parameter. false otherwise. /// Thrown when the Bundle instance has been disposed. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// bundle.AddItem("string", "a_string"); + /// string aString; + /// if (bundle.TryGetItem("string", out aString)) + /// { + /// Console.WriteLine(aString); + /// } + /// public bool TryGetItem(string key, out string value) { if (_keys.Contains(key) && Interop.Bundle.GetType(_handle, key) == (int)BundleType.String) @@ -354,6 +452,19 @@ namespace Tizen.Applications /// The value of the bundle item. If the key does not exist or the type of this parameter is incorrect, it is the default value for the value parameter type. /// true if an item with the key exists and if the value is the same type as the output value parameter. false otherwise. /// Thrown when the Bundle instance has been disposed. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// string[] stringArray = { "a", "b", "c" }; + /// bundle.AddItem("string_array", stringArray); + /// System.Collections.Generic.IEnumerable aStringArray; + /// if (bundle.TryGetItem("string", out aStringArray)) + /// { + /// foreach (string value in aStringArray) + /// { + /// Console.WriteLine(value); + /// } + /// } + /// public bool TryGetItem(string key, out IEnumerable value) { if (_keys.Contains(key) && Interop.Bundle.GetType(_handle, key) == (int)BundleType.StringArray) @@ -380,6 +491,20 @@ namespace Tizen.Applications /// true if the item is of the specified type. false otherwise. /// Thrown when the key does not exist or when there is an invalid parameter. /// Thrown when the Bundle instance has been disposed. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// string[] stringArray = { "a", "b", "c" }; + /// bundle.AddItem("string_array", stringArray); + /// if (bundle.Is("string_array")) + /// { + /// Console.WriteLine("It is a string[]"); + /// string[] anArray = bundle.GetItem("string_array"); + /// foreach (string value in anArray) + /// { + /// Console.WriteLine(value); + /// } + /// } + /// public bool Is(string key) { if (_keys.Contains(key)) @@ -413,6 +538,17 @@ namespace Tizen.Applications /// true if the item is successfully found and removed. false otherwise (even if the item is not found). /// Thrown when there is an invalid parameter. /// Thrown when the Bundle instance has been disposed. + /// + /// Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); + /// bundle.AddItem("string", "a_string"); + /// if (bundle.Contains("string")) + /// { + /// if (bundle.RemoveItem("string")) + /// { + /// Console.WriteLine("Removed"); + /// } + /// } + /// public bool RemoveItem(string key) { if (_keys.Contains(key)) -- 2.7.4