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#
Copy
public class Bundle : IDisposable
Inheritance
Bundle
Implements

Constructors

View Source

Bundle()

The bundle constructor.

Declaration
C#
Copy
public Bundle()
Examples
Copy
Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle();
Exceptions
Type Condition
InvalidOperationException

Thrown when out of memory.

API Level: 3
View Source

Bundle(SafeBundleHandle)

The bundle constructor.

Declaration
C#
Copy
public Bundle(SafeBundleHandle handle)
Parameters
Type Name Description
SafeBundleHandle handle

The SafeBundleHandle instance.

Exceptions
Type Condition
ArgumentNullException

Thrown when the handle is null or invalid.

API Level: 3

Properties

View Source

Count

The number of items in a bundle object.

Declaration
C#
Copy
public int Count { get; }
Property Value
Type Description
Int32
Examples
Copy
Tizen.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
View Source

Keys

The keys in a bundle object.

Declaration
C#
Copy
public IEnumerable<string> Keys { get; }
Property Value
Type Description
IEnumerable<String>
Examples
Copy
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); }
API Level: 3
View Source

SafeBundleHandle

Gets the SafeBundleHandle instance.

Declaration
C#
Copy
public SafeBundleHandle SafeBundleHandle { get; }
Property Value
Type Description
SafeBundleHandle
API Level: 3

Methods

View Source

AddItem(String, Byte[])

Adds an item into the bundle.

Declaration
C#
Copy
public void AddItem(string key, byte[] value)
Parameters
Type Name Description
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.

Byte[] value

The value of the item.

Examples
Copy
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);
Exceptions
Type Condition
ArgumentException

Thrown when the key already exists or when there is an invalid parameter.

ArgumentNullException

Thrown when a value is null.

InvalidOperationException

Thrown when out of memory or when the bundle instance has been disposed.

API Level: 3
View Source

AddItem(String, Byte[], Int32, Int32)

Adds an item into the bundle.

Declaration
C#
Copy
public void AddItem(string key, byte[] value, int offset, int count)
Parameters
Type Name Description
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.

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
Copy
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);
Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown when the offset or count is out of range.

ArgumentException

Thrown when the key already exists or when there is an invalid parameter.

ArgumentNullException

Thrown when a value is null.

InvalidOperationException

Thrown when out of memory or when the bundle instance has been disposed.

API Level: 3
View Source

AddItem(String, IEnumerable<String>)

Adds an item into the bundle.

Declaration
C#
Copy
public void AddItem(string key, IEnumerable<string> value)
Parameters
Type Name Description
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.

IEnumerable<String> value

The value of the item.

Examples
Copy
Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); string[] stringArray = { "a", "b", "c" }; bundle.AddItem("string_array", stringArray);
Exceptions
Type Condition
ArgumentException

Thrown when the key already exists or when there is an invalid parameter.

InvalidOperationException

Thrown when out of memory or when the bundle instance has been disposed.

API Level: 3
View Source

AddItem(String, String)

Adds an item into the bundle.

Declaration
C#
Copy
public void AddItem(string key, string value)
Parameters
Type Name Description
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.

String value

The value of the item.

Examples
Copy
Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); bundle.AddItem("string", "a_string");
Exceptions
Type Condition
ArgumentException

Thrown when the key already exists or when there is an invalid parameter.

InvalidOperationException

Thrown when out of memory or when the bundle instance has been disposed.

API Level: 3
View Source

Contains(String)

Checks whether the bundle contains an item with a specified key.

Declaration
C#
Copy
public bool Contains(string key)
Parameters
Type Name Description
String key

The key to check for.

Returns
Type Description
Boolean

true if the bundle contains the key, false otherwise.

Examples
Copy
Tizen.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
View Source

Decode(String)

Decodes an encoded bundle data.

Declaration
C#
Copy
public static Bundle Decode(string bundleRaw)
Parameters
Type Name Description
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
Copy
Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); string bundleRaw = bundle.Encode(); Bundle data = bundle.Decode(bundleRaw);
Exceptions
Type Condition
ArgumentException

Thrown when there is an invalid parameter.

API Level: 3
View Source

Dispose()

Releases any unmanaged resources used by this object.

Declaration
C#
Copy
public void Dispose()
API Level: 3
View Source

Dispose(Boolean)

Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.

Declaration
C#
Copy
protected 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
View Source

Encode()

Encodes bundle to string.

Declaration
C#
Copy
public string Encode()
Returns
Type Description
String

Encoded bundle data in string.

Examples
Copy
Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle(); string bundleRaw = bundle.Encode();
Exceptions
Type Condition
InvalidOperationException

Thrown when out of memory or when the bundle instance has been disposed.

API Level: 3
View Source

Finalize()

Destructor of the bundle class.

Declaration
C#
Copy
protected void Finalize()
View Source

GetItem(String)

Gets the value of a bundle item with a specified key.

Declaration
C#
Copy
public object GetItem(string key)
Parameters
Type Name Description
String key

The key of the bundle item whose value is desired.

Returns
Type Description
Object

The value of the bundle item.

Examples
Copy
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");) { string aString = (string)aValue; Console.WriteLine(aString); } }
Exceptions
Type Condition
ArgumentException

Thrown when the key does not exist or when there is an invalid parameter.

InvalidOperationException

Thrown when the bundle instance has been disposed.

API Level: 3
View Source

GetItem<T>(String)

Gets the value of a bundle item with a specified key. Note that this is a generic method.

Declaration
C#
Copy
public T GetItem<T>(string key)
Parameters
Type Name Description
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
Copy
Tizen.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
ArgumentException

Thrown when the key does not exist or when there is an invalid parameter.

InvalidCastException

Thrown when the value of the bundle item cannot be converted to the specified generic type.

InvalidOperationException

Thrown when the bundle instance has been disposed.

API Level: 3
View Source

Is<T>(String)

Checks whether an item is of a specific type.

Declaration
C#
Copy
public bool Is<T>(string key)
Parameters
Type Name Description
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
Copy
Tizen.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
ArgumentException

Thrown when the key does not exist or when there is an invalid parameter.

InvalidOperationException

Thrown when the bundle instance has been disposed.

API Level: 3
View Source

RemoveItem(String)

Removes a bundle item with a specific key from a Bundle.

Declaration
C#
Copy
public bool RemoveItem(string key)
Parameters
Type Name Description
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
Copy
Tizen.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
ArgumentException

Thrown when there is an invalid parameter.

InvalidOperationException

Thrown when the bundle instance has been disposed.

API Level: 3
View Source

TryGetItem(String, out Byte[])

Gets the value of a bundle item with a specified key.

Declaration
C#
Copy
public bool TryGetItem(string key, out byte[] value)
Parameters
Type Name Description
String key

The key of the bundle item whose value is desired.

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
Copy
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]); }
Exceptions
Type Condition
InvalidOperationException

Thrown when the bundle instance has been disposed.

API Level: 3
View Source

TryGetItem(String, out IEnumerable<String>)

Gets the value of a bundle item with a specified key.

Declaration
C#
Copy
public bool TryGetItem(string key, out IEnumerable<string> value)
Parameters
Type Name Description
String key

The key of the bundle item whose value is desired.

IEnumerable<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
Copy
Tizen.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
InvalidOperationException

Thrown when the bundle instance has been disposed.

API Level: 3
View Source

TryGetItem(String, out String)

Gets the value of a bundle item with a specified key.

Declaration
C#
Copy
public bool TryGetItem(string key, out string value)
Parameters
Type Name Description
String key

The key of the bundle item whose value is desired.

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
Copy
Tizen.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
InvalidOperationException

Thrown when the bundle instance has been disposed.

API Level: 3

Implements