Class Bundle
Definition
- Namespace:
- Tizen.Applications
- Assembly:
- Tizen.Applications.Common.dll
- API Level:
- 3
A bundle object represents a bundle. A bundle holds items (key-value pairs) and can be used with other Tizen APIs. Keys can be used to access values. This class is accessed by using a constructor to create a new instance of this object. A bundle instance is not guaranteed to be thread safe if the instance is modified by multiple threads.
C#Copypublic class Bundle : IDisposable
- Inheritance
-
System.ObjectBundle
- Implements
-
System.IDisposable
Constructors
Declaration
C#Copypublic Bundle()
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle();
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when out of memory. |
API Level: 3
Declaration
C#Copypublic Bundle(SafeBundleHandle handle)
Parameters
Type | Name | Description |
---|---|---|
SafeBundleHandle | handle | The SafeBundleHandle instance. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when the handle is null or invalid. |
API Level: 3
Properties
Declaration
C#Copypublic int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); bundle.AddItem("string", "a_string"); Console.WriteLine("There are {0} items in the bundle", bundle.Count);
API Level: 3
Declaration
C#Copypublic IEnumerable<string> Keys { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.String> |
Examples
CopyTizen.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); }
API Level: 3
Declaration
C#Copypublic SafeBundleHandle SafeBundleHandle { get; }
Property Value
Type | Description |
---|---|
SafeBundleHandle |
API Level: 3
Methods
Declaration
C#Copypublic void AddItem(string key, byte[] value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key to identify the item with. If an item with the key already exists in the bundle, this method will not succeed. |
System.Byte[] | value | The value of the item. |
Examples
CopyTizen.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);
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when the key already exists or when there is an invalid parameter. |
System.ArgumentNullException | Thrown when a value is null. |
System.InvalidOperationException | Thrown when out of memory or when the bundle instance has been disposed. |
API Level: 3
Declaration
C#Copypublic void AddItem(string key, byte[] value, int offset, int count)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key to identify the item with. If an item with the key already exists in the bundle, this method will not succeed. |
System.Byte[] | value | The value of the item. |
Int32 | offset | The zero-based byte offset in value from which to add to the bundle. |
Int32 | count | The maximum number of bytes to add to the bundle starting with offset. |
Examples
CopyTizen.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);
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | Thrown when the offset or count is out of range. |
System.ArgumentException | Thrown when the key already exists or when there is an invalid parameter. |
System.ArgumentNullException | Thrown when a value is null. |
System.InvalidOperationException | Thrown when out of memory or when the bundle instance has been disposed. |
API Level: 3
Declaration
C#Copypublic void AddItem(string key, IEnumerable<string> value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key to identify the item with. If an item with the key already exists in the bundle, this method will not succeed. |
System.Collections.Generic.IEnumerable<System.String> | value | The value of the item. |
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); string[] stringArray = { "a", "b", "c" }; bundle.AddItem("string_array", stringArray);
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when the key already exists or when there is an invalid parameter. |
System.InvalidOperationException | Thrown when out of memory or when the bundle instance has been disposed. |
API Level: 3
Declaration
C#Copypublic void AddItem(string key, string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key to identify the item with. If an item with the key already exists in the bundle, this method will not succeed. |
System.String | value | The value of the item. |
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); bundle.AddItem("string", "a_string");
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when the key already exists or when there is an invalid parameter. |
System.InvalidOperationException | Thrown when out of memory or when the bundle instance has been disposed. |
API Level: 3
Declaration
C#Copypublic bool Contains(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key to check for. |
Returns
Type | Description |
---|---|
Boolean | true if the bundle contains the key, false otherwise. |
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); bundle.AddItem("string", "a_string"); if (bundle.Contains("string")) { string aValue = bundle.GetItem<string>("string"); Console.WriteLine(aValue); }
API Level: 3
Declaration
C#Copypublic static Bundle Decode(string bundleRaw)
Parameters
Type | Name | Description |
---|---|---|
System.String | bundleRaw | The encoded bundle data. bundleRaw should be the returned value of Tizen.Applications.Bundle.Encode, otherwise this method will not succeed. |
Returns
Type | Description |
---|---|
Bundle | Decoded Bundle object. |
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); string bundleRaw = bundle.Encode(); Bundle data = bundle.Decode(bundleRaw);
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when there is an invalid parameter. |
API Level: 3
Declaration
C#Copypublic void Dispose()
API Level: 3
Dispose(Boolean)
Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
Declaration
C#Copyprotected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing | If true, disposes any disposable objects. If false, does not dispose disposable objects. |
API Level: 3
Declaration
C#Copypublic string Encode()
Returns
Type | Description |
---|---|
System.String | Encoded bundle data in string. |
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); string bundleRaw = bundle.Encode();
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when out of memory or when the bundle instance has been disposed. |
API Level: 3
Declaration
C#Copyprotected void Finalize()
Declaration
C#Copypublic object GetItem(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key of the bundle item whose value is desired. |
Returns
Type | Description |
---|---|
System.Object | The value of the bundle item. |
Examples
CopyTizen.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");) { string aString = (string)aValue; Console.WriteLine(aString); } }
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when the key does not exist or when there is an invalid parameter. |
System.InvalidOperationException | Thrown when the bundle instance has been disposed. |
API Level: 3
GetItem<T>(String)
Gets the value of a bundle item with a specified key. Note that this is a generic method.
Declaration
C#Copypublic T GetItem<T>(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key of the bundle item whose value is desired. |
Returns
Type | Description |
---|---|
T | The value of the bundle item if it is of the specified generic type. |
Type Parameters
Name | Description |
---|---|
T | The generic type to return. |
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); string[] stringArray = { "a", "b", "c" }; bundle.AddItem("string_array", stringArray); if (bundle.Is<string>("string_array")) { Console.WriteLine("It is a string"); Console.WriteLine(bundle.GetItem<string>("string_array")); } else if (bundle.Is<string[]>("string_array")) { Console.WriteLine("It is a string[]"); string[] anArray = bundle.GetItem<string[]>("string_array"); foreach (string value in anArray) { Console.WriteLine(value); } }
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when the key does not exist or when there is an invalid parameter. |
System.InvalidCastException | Thrown when the value of the bundle item cannot be converted to the specified generic type. |
System.InvalidOperationException | Thrown when the bundle instance has been disposed. |
API Level: 3
Declaration
C#Copypublic bool Is<T>(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key whose type wants to be checked. |
Returns
Type | Description |
---|---|
Boolean | true if the item is of the specified type, false otherwise. |
Type Parameters
Name | Description |
---|---|
T | The generic type to check for. |
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); string[] stringArray = { "a", "b", "c" }; bundle.AddItem("string_array", stringArray); if (bundle.Is<string[]>("string_array")) { Console.WriteLine("It is a string[]"); string[] anArray = bundle.GetItem<string[]>("string_array"); foreach (string value in anArray) { Console.WriteLine(value); } }
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when the key does not exist or when there is an invalid parameter. |
System.InvalidOperationException | Thrown when the bundle instance has been disposed. |
API Level: 3
Declaration
C#Copypublic bool RemoveItem(string key)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key of the item to delete. |
Returns
Type | Description |
---|---|
Boolean | true if the item is successfully found and removed, false otherwise (even if the item is not found). |
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); bundle.AddItem("string", "a_string"); if (bundle.Contains("string")) { if (bundle.RemoveItem("string")) { Console.WriteLine("Removed"); } }
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when there is an invalid parameter. |
System.InvalidOperationException | Thrown when the bundle instance has been disposed. |
API Level: 3
Declaration
C#Copypublic bool TryGetItem(string key, out byte[] value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key of the bundle item whose value is desired. |
System.Byte[] | value | 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. |
Returns
Type | Description |
---|---|
Boolean | true if an item with the key exists and if the value is the same type as the output value parameter, false otherwise. |
Examples
CopyTizen.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]); }
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the bundle instance has been disposed. |
API Level: 3
TryGetItem(String, out IEnumerable<String>)
Gets the value of a bundle item with a specified key.
Declaration
C#Copypublic bool TryGetItem(string key, out IEnumerable<string> value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key of the bundle item whose value is desired. |
System.Collections.Generic.IEnumerable<System.String> | value | 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. |
Returns
Type | Description |
---|---|
Boolean | true if an item with the key exists and if the value is the same type as the output value parameter, false otherwise. |
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); string[] stringArray = { "a", "b", "c" }; bundle.AddItem("string_array", stringArray); System.Collections.Generic.IEnumerable<string> aStringEnumerable; if (bundle.TryGetItem("string", out aStringEnumerable)) { foreach (string value in aStringEnumerable) { Console.WriteLine(value); } }
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the bundle instance has been disposed. |
API Level: 3
Declaration
C#Copypublic bool TryGetItem(string key, out string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | The key of the bundle item whose value is desired. |
System.String | value | 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. |
Returns
Type | Description |
---|---|
Boolean | true if an item with the key exists and if the value is the same type as the output value parameter, false otherwise. |
Examples
CopyTizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); bundle.AddItem("string", "a_string"); string aString; if (bundle.TryGetItem("string", out aString)) { Console.WriteLine(aString); }
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when the bundle instance has been disposed. |