Class Bundle
Definition
- Namespace:
- Tizen.Applications
- Assembly:
- Tizen.Applications.Common.dll
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.
public class Bundle : IDisposable
- Inheritance
-
objectBundle
- Implements
-
System.IDisposable
Constructors
View SourceBundle()
The bundle constructor.
Declaration
public Bundle()
Examples
Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle();
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when out of memory. |
Bundle(SafeBundleHandle)
The bundle constructor.
Declaration
public 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. |
Properties
View SourceCount
The number of items in a bundle object.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
int |
Examples
Tizen.Applications.Bundle bundle = new Tizen.Applications.Bundle();
bundle.AddItem("string", "a_string");
Console.WriteLine("There are {0} items in the bundle", bundle.Count);
View Source
Keys
The keys in a bundle object.
Declaration
public IEnumerable<string> Keys { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><string> |
Examples
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);
}
View Source
SafeBundleHandle
Gets the SafeBundleHandle instance.
Declaration
public SafeBundleHandle SafeBundleHandle { get; }
Property Value
Type | Description |
---|---|
SafeBundleHandle |
Methods
View SourceAddItem(string, byte[], int, int)
Adds an item into the bundle.
Declaration
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. |
int | offset | The zero-based byte offset in value from which to add to the bundle. |
int | count | The maximum number of bytes to add to the bundle starting with offset. |
Examples
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 |
---|---|
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. |
AddItem(string, byte[])
Adds an item into the bundle.
Declaration
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
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 |
---|---|
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. |
AddItem(string, IEnumerable<string>)
Adds an item into the bundle.
Declaration
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. |
System.Collections.Generic.IEnumerable<T><string> | value | The value of the item. |
Examples
Tizen.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. |
AddItem(string, string)
Adds an item into the bundle.
Declaration
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
Tizen.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. |
Contains(string)
Checks whether the bundle contains an item with a specified key.
Declaration
public bool Contains(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key to check for. |
Returns
Type | Description |
---|---|
bool | true if the bundle contains the key, false otherwise. |
Examples
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);
}
View Source
Decode(string)
Decodes an encoded bundle data.
Declaration
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
Tizen.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. |
Dispose()
Releases any unmanaged resources used by this object.
Declaration
public void Dispose()
Dispose(bool)
Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | If true, disposes any disposable objects. If false, does not dispose disposable objects. |
Encode()
Encodes bundle to string.
Declaration
public string Encode()
Returns
Type | Description |
---|---|
string | Encoded bundle data in string. |
Examples
Tizen.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. |
~Bundle()
Destructor of the bundle class.
Declaration
protected ~Bundle()
GetItem(string)
Gets the value of a bundle item with a specified key.
Declaration
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
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 |
---|---|
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. |
GetItem<T>(string)
Gets the value of a bundle item with a specified key. Note that this is a generic method.
Declaration
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
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 |
---|---|
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. |
Is<T>(string)
Checks whether an item is of a specific type.
Declaration
public bool Is<T>(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key whose type wants to be checked. |
Returns
Type | Description |
---|---|
bool | true if the item is of the specified type, false otherwise. |
Type Parameters
Name | Description |
---|---|
T | The generic type to check for. |
Examples
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 |
---|---|
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. |
RemoveItem(string)
Removes a bundle item with a specific key from a Bundle.
Declaration
public bool RemoveItem(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key of the item to delete. |
Returns
Type | Description |
---|---|
bool | true if the item is successfully found and removed, false otherwise (even if the item is not found). |
Examples
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 |
---|---|
System.ArgumentException | Thrown when there is an invalid parameter. |
System.InvalidOperationException | Thrown when the bundle instance has been disposed. |
TryGetItem(string, out byte[])
Gets the value of a bundle item with a specified key.
Declaration
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 |
---|---|
bool | true if an item with the key exists and if the value is the same type as the output value parameter, false otherwise. |
Examples
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 |
---|---|
System.InvalidOperationException | Thrown when the bundle instance has been disposed. |
TryGetItem(string, out IEnumerable<string>)
Gets the value of a bundle item with a specified key.
Declaration
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. |
System.Collections.Generic.IEnumerable<T><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 |
---|---|
bool | true if an item with the key exists and if the value is the same type as the output value parameter, false otherwise. |
Examples
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 |
---|---|
System.InvalidOperationException | Thrown when the bundle instance has been disposed. |
TryGetItem(string, out string)
Gets the value of a bundle item with a specified key.
Declaration
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 |
---|---|
bool | true if an item with the key exists and if the value is the same type as the output value parameter, false otherwise. |
Examples
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 |
---|---|
System.InvalidOperationException | Thrown when the bundle instance has been disposed. |