Class ResourceOptions
Definition
- Namespace:
- Tizen.Network.IoTConnectivity
- Assembly:
- Tizen.Network.IoTConnectivity.dll
- API Level:
- 3
This class represents resource options. It provides APIs to manage them.
The iotcon options API provides methods for managing vendor specific options of coap packet.
See more about coap packet in http://tools.ietf.org/html/rfc7252.
C#Copypublic class ResourceOptions : IDictionary<ushort, string>, ICollection<KeyValuePair<ushort, string>>, IEnumerable<KeyValuePair<ushort, string>>, IEnumerable, IDisposable
- Inheritance
-
System.ObjectResourceOptions
- Implements
-
System.Collections.Generic.IDictionary<System.UInt16, System.String>System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.UInt16, System.String>>System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.UInt16, System.String>>System.Collections.IEnumerableSystem.IDisposable
Constructors
Declaration
C#Copypublic ResourceOptions()
Examples
CopyResourceOptions options = new ResourceOptions();
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Thrown when the iotcon is not supported. |
OutOfMemoryException | Thrown when there is not enough memory. |
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
Properties
Declaration
C#Copypublic int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The number of options. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); options.Add(2055, "sample value"); var count = options.Count; Console.WriteLine("There are {0} keys in the options object", count);
API Level: 3
Declaration
C#Copypublic bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean | Whether the collection is readonly. |
Examples
CopyResourceOptions options = new ResourceOptions(); if (options.IsReadOnly) Console.WriteLine("Read only options");
API Level: 3
Declaration
C#Copypublic string this[ushort key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | key | The option ID to get or set. |
Property Value
Type | Description |
---|---|
System.String | The option data. |
Examples
CopyResourceOptions options = new ResourceOptions(); options[2055] = "sample-data"; Console.WriteLine("Option has : {0}", options[2055]);
API Level: 3
Declaration
C#Copypublic ICollection<ushort> Keys { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<System.UInt16> | All the Option keys. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); options.Add(2055, "sample value"); var keys = options.Keys; Console.WriteLine("Resource options contains keys {0} and {1}", keys.ElementAt(0), keys.ElementAt(1));
API Level: 3
Declaration
C#Copypublic ICollection<string> Values { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<System.String> | All the Option values. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); options.Add(2055, "sample value"); var values = options.Values; Console.WriteLine("Resource options contains values {0} and {1}", values.ElementAt(0), values.ElementAt(1));
API Level: 3
Methods
Declaration
C#Copypublic void Add(KeyValuePair<ushort, string> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<System.UInt16, System.String> | item | The key value pair. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345"));
See Also
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
Declaration
C#Copypublic void Add(ushort key, string value)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | key | The ID of the option to insert. |
System.String | value | The string data to insert into the options. |
Remarks
ResourceOptions can have up to 2 options.
key is always situated between 2048 and 3000.
Length of option data is less than or equal to 15.
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data");
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Thrown when the iotcon is not supported. |
System.ArgumentException | Thrown when there is an invalid parameter. |
See Also
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
Declaration
C#Copypublic void Clear()
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "12345"); options.Add(2055, "sample"); options.Clear();
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Thrown when the iotcon is not supported. |
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
Declaration
C#Copypublic bool Contains(KeyValuePair<ushort, string> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<System.UInt16, System.String> | item | The key value pair. |
Returns
Type | Description |
---|---|
System.Boolean | True if exists. Otherwise, false. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345")); var isPresent = options.Contains(new KeyValuePair<ushort, string>(2050, "12345")); if (isPresent) Console.WriteLine("Key value pair is present");
API Level: 3
Declaration
C#Copypublic bool ContainsKey(ushort key)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | key | The key to look for. |
Returns
Type | Description |
---|---|
System.Boolean | true if exists. Otherwise, false. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); if (options.ContainsKey(2050)) Console.WriteLine("options conatins key : 2050");
API Level: 3
CopyTo(KeyValuePair<UInt16, String>[], Int32)
Copies the elements of the options collection to an array, starting at a particular index.
Declaration
C#Copypublic void CopyTo(KeyValuePair<ushort, string>[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<System.UInt16, System.String>[] | array | The destination array. |
System.Int32 | arrayIndex | Index parameter. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345")); KeyValuePair<ushort, string>[] dest = new KeyValuePair<ushort, string>[options.Count]; options.CopyTo(dest, 0); Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value);
API Level: 3
Declaration
C#Copypublic void Dispose()
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
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 |
---|---|---|
System.Boolean | disposing | If true, disposes any disposable objects. If false, does not dispose disposable objects. |
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
Declaration
C#Copyprotected void Finalize()
Declaration
C#Copypublic IEnumerator<KeyValuePair<ushort, string>> GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<System.UInt16, System.String>> | Enumerator to option pairs. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "sample1")); options.Add(new KeyValuePair<ushort, string>(2055, "sample2")); foreach (KeyValuePair<string, object> pair in options) { Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); }
API Level: 3
Declaration
C#Copypublic bool Remove(KeyValuePair<ushort, string> item)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<System.UInt16, System.String> | item | The key value pair to remove |
Returns
Type | Description |
---|---|
System.Boolean | True if operation is successful. Otherwise, false |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345")); var result = options.Remove(new KeyValuePair<ushort, string>(2050, "12345"));
Exceptions
Type | Condition |
---|---|
System.ArgumentException | Thrown when there is an invalid parameter |
See Also
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
Declaration
C#Copypublic bool Remove(ushort key)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | key | The ID of the option to delete. |
Returns
Type | Description |
---|---|
System.Boolean | True if operation is successful. Otherwise, false. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "12345"); var result = options.Remove(2050);
Exceptions
Type | Condition |
---|---|
System.NotSupportedException | Thrown when the iotcon is not supported. |
System.ArgumentException | Thrown when there is an invalid parameter. |
See Also
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
Declaration
C#Copypublic bool TryGetValue(ushort key, out string value)
Parameters
Type | Name | Description |
---|---|---|
System.UInt16 | key | The option ID. |
System.String | value | Value corresponding to option ID. |
Returns
Type | Description |
---|---|
System.Boolean | True if the key exists, false otherwise. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(2050, "12345"); string value; var isPresent = options.TryGetValue(2050, out value); if (isPresent) Console.WriteLine("value : {0}", value);
API Level: 3
Explicit Interface Implementations
Declaration
C#CopyIEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
System.Collections.IEnumerator | Enumerator to option pairs. |
Examples
CopyResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "sample1")); options.Add(new KeyValuePair<ushort, string>(2055, "sample2")); foreach (KeyValuePair<string, object> pair in options) { Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); }